Skip to content
Daniel Marshall edited this page Aug 20, 2015 · 42 revisions

This tutorial will get you started with using the FamilySearch gedcomx-php SDK. Start here and complete each section of this document in sequence.

It is required that you complete the prerequisites outlined in previous steps before proceeding.

##Set Up a Project

  • Create a new folder for your PHP project. This folder can be located anywhere on your computer. You simply need to know where it is. For greatest ease, your project should be accessible through a web server. The web server you use should allow browser access to your files at URL http://localhost. If you do not have a web server to use, the tutorial app can be run using the internal PHP web server.

  • Download or copy the tutorial.php gist file into your project folder.

Start the PHP Server

If you want to use the PHP server for testing, open a console, move to your PHP project folder, and enter the following command:

php -S localhost:5000

Run and Edit tutorial.php

To complete the tutorial you will need to alternate between running and editing the tutorial.php file.

  • From a browser, run the tutorial.php app using the following URL and follow the on-screen instructions:

http://localhost:5000/tutorial.php

  • You will need your app key for the first step of the tutorial. You can find your app key on the FamilySearch Developer website on the My Apps page.

Use the PHP SDK Documentation

To orient you on how to navigate the PHP SDK documentation, it would be helpful to walk you through the process of getting the name of a person in the Family Tree.

Activity: Open the PHP SDK documentation and enter FamilySearchClient in the Search box to find the FamilySearchClient class. From there follow the states listed in the following steps and locate the methods in the documentation. As you go, notice some of the other methods that are available in the various states. You can also examine tutorial.php or the sample app code to see how to code the methods.

Steps to Instantiate a Client

  1. You must first populate a FamilySearchClient class array with an app key, a redirect URI, and an access token. The FamilySearchClient class contains the _construct method along with other methods. Can you find the array in the documentation?

  2. With the array populated you must use the PHP "new" command to create a FamilySearchClient class instance (see the tutorial.php file to see how this is done). This places you in the FamilySearchClient state. You must transition from one "class" state to another by executing methods that are in the current state.

Steps to Authenticate

  1. Use the getOAuth2AuthorizationURI() method to ask the user to login.

  2. Use the authenticateViaOAuth2AuthCode($code) method and the getAccessToken() getter to retrieve the authorized access token.

Steps to Get a Name

After authenticating with FamilySearch, the following steps will transition you from state to state in order to obtain information about a person you have identified by person ID. These steps show how to get the person's name.

  1. Use the familytree() method to transition to the FamilyTreeCollectionState.

  2. Use the readPersonById() method to transition to the FamilyTreePersonState.

  3. The FamilyTreePersonState inherits the getPerson() method from the PersonState. Use the getPerson() method to transition to the Person state.

  4. Use the getDisplayExtension() method to retrieve the DisplayProperties.

  5. Get the person's name from the DisplayProperties by using the getName() getter.

What Next?

You might want to examine the sample app as your next step, or simply get started coding on your own.

Home

Tutorial

  • Step 1: Register
  • Step 2: Set up your test environment
  • Step 3: Build tutorial.php
  • Step 4: Use the SDK Documentation

Sample App

Documentation

Design

Clone this wiki locally