Menu

Tree [c57935] master /
 History

HTTPS access


File Date Author Commit
 docs 2016-04-19 Nick Matthews Nick Matthews [e4e6df] Setting Birthday variables to private, moving B...
 src 2016-05-25 Nino Nino [1abcc6] Corrected phpDoc comment for binToHex
 tests 2016-05-25 Andreas Möller Andreas Möller [1f54c6] Fix: Move test assets to Fixtures namespace
 .gitattributes 2015-10-13 Emanuele Minotto Emanuele Minotto [b192bb] added .gitattributes
 .gitignore 2016-04-19 Fosco Marotto Fosco Marotto [40c74a] Updating per feedback.
 .scrutinizer.yml 2016-05-21 Andreas Möller Andreas Möller [7379ae] Enhancement: Require code in tests/ to be PSR-2...
 .travis.yml 2016-05-21 Andreas Möller Andreas Möller [d8dd22] Enhancement: Extract configuration file for phpcs
 CHANGELOG.md 2016-05-23 Fosco Marotto Fosco Marotto [5d1a9f] Added a note to changelog.
 CONTRIBUTING.md 2016-05-21 Andreas Möller Andreas Möller [d8dd22] Enhancement: Extract configuration file for phpcs
 LICENSE 2016-02-10 jfreed jfreed [80d7c6] Missed LICENSE and tests/FacebookTestCredential...
 README.md 2016-05-18 Sammy Kaye Powers Sammy Kaye Powers [c60fba] Update CHANGELOG and bump version
 composer.json 2016-02-10 Emanuele Minotto Emanuele Minotto [6727ff] Use Composer safe versions
 phpcs.xml.dist 2016-05-21 Andreas Möller Andreas Möller [7379ae] Enhancement: Require code in tests/ to be PSR-2...
 phpunit.xml.dist 2015-05-06 SammyK SammyK [cce152] Update 4.1 docs to refer to version 5

Read Me

Facebook SDK for PHP (v5)

Build Status
Scrutinizer Code Quality
Latest Stable Version

This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app.

Installation

The Facebook PHP SDK can be installed with Composer. Run this command:

composer require facebook/php-sdk-v4

Upgrading to v5.x

Upgrading from v4.x? Facebook PHP SDK v5.x introduced breaking changes. Please read the upgrade guide before upgrading.

Usage

Note: This version of the Facebook SDK for PHP requires PHP 5.4 or greater.

Simple GET example of a user's profile.

$fb = new Facebook\Facebook([
  'app_id' => '{app-id}',
  'app_secret' => '{app-secret}',
  'default_graph_version' => 'v2.6',
  //'default_access_token' => '{access-token}', // optional
]);

// Use one of the helper classes to get a Facebook\Authentication\AccessToken entity.
//   $helper = $fb->getRedirectLoginHelper();
//   $helper = $fb->getJavaScriptHelper();
//   $helper = $fb->getCanvasHelper();
//   $helper = $fb->getPageTabHelper();

try {
  // Get the Facebook\GraphNodes\GraphUser object for the current user.
  // If you provided a 'default_access_token', the '{access-token}' is optional.
  $response = $fb->get('/me', '{access-token}');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

$me = $response->getGraphUser();
echo 'Logged in as ' . $me->getName();

Complete documentation, installation instructions, and examples are available at: https://developers.facebook.com/docs/php

Tests

  1. Composer is a prerequisite for running the tests. Install composer globally, then run composer install to install required files.
  2. Create a test app on Facebook Developers, then create tests/FacebookTestCredentials.php from tests/FacebookTestCredentials.php.dist and edit it to add your credentials.
  3. The tests can be executed by running this command from the root directory:
$ ./vendor/bin/phpunit

By default the tests will send live HTTP requests to the Graph API. If you are without an internet connection you can skip these tests by excluding the integration group.

$ ./vendor/bin/phpunit --exclude-group integration

Contributing

For us to accept contributions you will have to first have signed the Contributor License Agreement. Please see CONTRIBUTING for details.

License

Please see the license file for more information.

MongoDB Logo MongoDB