Skip to content

Instantly share code, notes, and snippets.

@jimmyz
Created April 7, 2015 19:50
Show Gist options
  • Save jimmyz/c3dc084eda6d745a7503 to your computer and use it in GitHub Desktop.
Save jimmyz/c3dc084eda6d745a7503 to your computer and use it in GitHub Desktop.
Search for FamilySearch Family Tree Person
<?php
require 'vendor/autoload.php';
session_start();
use Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\FamilyTreeStateFactory;
use Gedcomx\Rs\Client\Util\GedcomxPersonSearchQueryBuilder;
use Gedcomx\Rs\Client\PersonSearchResultsState;
use Gedcomx\Conclusion\Person;
if(isset($_SESSION['fs_access_token'])){
$accessToken = $_SESSION['fs_access_token'];
$q = new GedcomxPersonSearchQueryBuilder();
$q
->givenName('John')
->surname('Hannon')
->gender('Male');
$stateFactory = new FamilyTreeStateFactory();
$searchResultsState = $stateFactory
->newCollectionState("https://sandbox.familysearch.org/platform/collections/tree") //read the collection
->authenticateWithAccessToken($accessToken) //set the Access Token
->searchForPersons($q->build()); //read the person
$count = $searchResultsState->getResults()->getResults();
echo $count;
$searchResultEntries = $searchResultsState->getResults()->getEntries();
echo "Results Page Count: ". count($searchResultEntries);
}else{
echo "Error: No access token";
exit;
}
?>
<html>
<head>
<title>Searching for Person John Hannon</title>
</head>
<body>
<?php foreach($searchResultEntries as $entry):
$person =$entry->getContent()->getGedcomx()->getPersons()[0];
?>
<table>
<tr>
<th>Field</th>
<th>Value</th>
</tr>
<tr>
<td>Full Name:</td>
<td><?= $person->getDisplayExtension()->getName(); ?></td>
</tr>
<tr>
<td>Birth Date:</td>
<td><?= $person->getDisplayExtension()->getBirthDate(); ?></td>
</tr>
<tr>
<td>Death Date:</td>
<td><?= $person->getDisplayExtension()->getDeathDate(); ?></td>
</tr>
</table>
<?php endforeach; ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment