FamilySearch / gedcomx-php

PHP SDK for GEDCOM X Processing. See the documentation at
http://familysearch.github.io/gedcomx-php/
Other
35 stars 15 forks source link

FamilySearchClient #34

Closed justincy closed 9 years ago

justincy commented 9 years ago

This is for #24 and #26.

Example usage:

<?php

use Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchClient;    

$client = new FamilySearchClient(array(
    'redirectURI' => 'http://localhost:5000/familysearch-auth.php',
    'clientId' => 'a0T3000000BfM3mEAF',
    'environment' => 'sandbox', // Sandbox is default so this is not necessary
    'pendingModfications' => ['remove-identity-v2-login','301-on-updates-to-merged-entities']
));

if($_GET['code']) {
    $client->authenticateViaOAuth2AuthCode($_GET['code']);
    session_start();
    $_SESSION['fs_access_token'] = $client->getAccessToken();
    header('Location: /index.php');
} else {
    header('Location: '.$client->getOAuth2AuthorizationURI());
}
<?php

use Gedcomx\Extensions\FamilySearch\Rs\Client\FamilySearchClient;  

if(isset($_SESSION['fs_access_token'])){
  $client = new FamilySearch\Client(array(
    // When setting the accessToken, that's all you need
    'accessToken'=> $_SESSION['fs_access_token']
  ));

  $personState = $client->familytree()->readCurrentUserPerson();
  $person = $personState->getPerson();
  echo $person->getFullName();

  $personState = $client->familytree()->readPerson('KWQS-BBQ');
  $person = $personState->getPerson();
  echo $person->getFullName();

} else {
  header('Location: familysearch-auth.php');
}

Internally, it maps the environment param to the proper collections URI then uses that resource to lookup the URI for the family tree collection.

jimmyz commented 9 years ago

Looks like the build failed: https://travis-ci.org/FamilySearch/gedcomx-php/jobs/67089203

justincy commented 9 years ago

Build failed again but this time it's not my fault.

jimmyz commented 9 years ago

The tests are really fragile. The sandbox seems to be producing inconsistent results. I'm going to merge.