Created
April 7, 2015 19:50
-
-
Save jimmyz/c3dc084eda6d745a7503 to your computer and use it in GitHub Desktop.
Search for FamilySearch Family Tree Person
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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