getPersonSearch
by Dovy Paukstys
HTML
<script src="http://rootsdev.org/familysearch-javascript-sdk/familysearch-javascript-sdk.js"></script>
<script src="http://public.werelate.org/prettyprint.js"></script>
<a id="run" href="#">Run</a>
<div id="output" />
JavaScript
function run() {
client.getAccessToken().then(function () {
client.getPersonSearch({
surname: 'Quass'
}).then(function (response) {
var results = response.getSearchResults();
console.log(response);
output('Results Metadata', {
'Count': response.getResultsCount(),
'Index': response.getIndex(),
'Context': response.getContext()
});
for (var i = 0, len = results.length; i < len; i++) {
var result = results[i];
var primaryPerson = result.$getPrimaryPerson();
output('Search Result', {
'Id': result.id,
'Title': result.title,
'Score': result.score,
'Name': primaryPerson.$getDisplayName(),
'BirthDate': primaryPerson.$getBirthDate(),
'BirthPlace': primaryPerson.$getBirthPlace(),
'DeathDate': primaryPerson.$getDeathDate(),
'DeathPlace': primaryPerson.$getDeathPlace(),
'Father(s)': getRelativeData(result.$getFathers()),
'Mother(s)': getRelativeData(result.$getMothers()),
'Spouse(s)': getRelativeData(result.$getSpouses()),
'Children': getRelativeData(result.$getChildren())
});
}
output('Raw json response with convenience functions', response);
console.log(response);
});
});
}
function getRelativeData(persons) {
var data = [];
for (var i = 0, len = persons.length; i < len; i++) {
data.push({
'Id': persons[i].id,
'Name': persons[i].$getDisplayName()
});
}
return data;
}
var client = new FamilySearch({
app_key: 'WCQY-7J1Q-GKVV-7DNM-SQ5M-9Q5H-JX3H-CMJK',
environment: 'sandbox',
auth_callback: 'http://fiddle.jshell.net',
...