Facebook Instant Articles PHP SDK - Client


The Client component of this SDK is a simple wrapper around the Instant Articles API, which can be used for publishing Instant Articles on Facebook. The client provides a CRUD interface for Instant Articles as well as a helper for authentication. The client depends on the main Facebook SDK for PHP as an interface to the Graph API and Facebook Login.

The API Client is a lightweight layer on top of the Facebook SDK for PHP making it easy to push articles to your Facebook Page. Example:

$article = InstantArticle::create();
$transformer->transform($article, $someDocument);

// Instantiate an API client
$client = Client::create(
    false // Use development environment?

// Import the article
try {
    $client->importArticle($article, $publish);
} catch (Exception $e) {
    echo 'Could not import the article: '.$e->getMessage();

Helper class

Since publishing Instant Articles is done to an existing Facebook Page, the Client also contains a Helper class to simplify fetching the access token for Facebook Pages that you're an admin of. Example:

$userAccessToken = 'USER_ACCESS_TOKEN';

// Instantiate a client helper
$helper = Helper::create(

// Grab pages you are admin of and tokens
$pagesAndTokens = $helper->getPagesAndTokens($userAccessToken)->all();
foreach ($pagesAndTokens as $pageAndToken) {
    echo 'Page ID: ' . $pageAndToken->getField('id');
    echo 'Page name: ' . $pageAndToken->getField('name');
    echo 'Page access token: ' . $pageAndToken->getField('access_token');