-
Notifications
You must be signed in to change notification settings - Fork 2
Tutorial
NOTE: You must complete the previous steps of the tutorial before proceeding.
This tutorial app will get you started with the FamilySearch gedcomx-php SDK.
To complete the tutorial you will need to alternate between editing the tutorial.php file and running it in your browser.
- Copy the following code into a text file using your editor.
<title>PHP Tutorial: FamilySearch PHP SDK</title> getId(); $displayInfo = $person->getDisplayExtension(); ?>
ID Gender Birth Date Status = $personId; ?> = $displayInfo->getGender(); ?> = $displayInfo->getBirthDate(); ?> = $person->isLiving() ? 'Living' : 'Deceased'; ?>
- Name the file tutorial.php and save it in your project folder.
- From a browser, run the tutorial.php app using the following URL:
http://localhost:5000/tutorial.php
Your app must first authenticate a user with FamilySearch. To authenticate you must have an app key that has been assigned to your app by FamilySearch. This app key is used to obtain an access token which is required by each FamilySearch API endpoint.
- Insert the following AUTHENTICATION CODE into the tutorial.php file.
require '/vendor/autoload.php';
use Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchClient;
// INITIALIZE A PHP SESSION
session_start();
$clientOptions = array(
'environment' => 'sandbox',
// LOAD YOUR APP KEY (You can find your app key in "My Apps" on the FamilySearch developer site)
'clientId' => 'YOURAPPKEYGOESHERE',
'redirectURI' => 'http://localhost:5000/tutorial.php'
);
if(isset($_SESSION['fs_access_token'])){
$clientOptions['accessToken'] = $_SESSION['fs_access_token'];
}
// INSTANTIATE A CLIENT
$client = new FamilySearchClient($clientOptions);
- Find your app key in the FamilySearch Developer website on the My Apps page.
- Copy your app key into the designated line of the AUTHENTICATION CODE.
- Save tutorial.php and refresh the page that is running it in your browser.
With your access token you can now use any of the methods in the PHP SDK. Start by reading the current user in the FamilySearch Tree.
- Insert the following code at CURRENT USER in the tutorial.php file.
- Save tutorial.php and refresh the page that is running it in your browser.
You can specify search criteria to perform a search of people in the tree.
- Insert the following code at SEARCH in the tutorial.php file.
- Save tutorial.php and refresh the page that is running it in your browser.
- Perform a few searches to demonstrate the search capability.
If you know a person ID (PID) of someone in the Tree you can read the details of that person.
- Insert the following code at READ BY PERSON ID in the tutorial.php file.
- Save tutorial.php and refresh the page that is running it in your browser.
- Use a PID from your search to read that person by PID.