corenta/php53-graph-sdk

PHP 5.3+ Facebook SDK

5.7.1 2018-10-17 17:29 UTC

This package is auto-updated.

Last update: 2024-09-20 14:20:08 UTC


README

本仓库包含开源PHP SDK,允许您从PHP应用程序访问Facebook平台。

安装

Facebook PHP SDK可以使用Composer安装。运行以下命令:

composer require corenta/php53-graph-sdk

使用

用户资料简单GET示例。

require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

$fb = new \Facebook\Facebook(array(
  'app_id' => '{app-id}',
  'app_secret' => '{app-secret}',
  'default_graph_version' => 'v2.10',
  //'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();

完整文档、安装说明和示例可在此处找到。

测试

  1. 运行测试需要Composer。全局安装Composer,然后运行composer install安装所需文件。
  2. Facebook开发者上创建测试应用程序,然后从tests/FacebookTestCredentials.php.dist创建tests/FacebookTestCredentials.php并编辑它以添加您的凭证。
  3. 可以从根目录运行此命令来执行测试:
$ ./vendor/bin/phpunit

默认情况下,测试将向Graph API发送实时HTTP请求。如果您没有互联网连接,可以排除integration组以跳过这些测试。

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

贡献

许可证

有关更多信息,请参阅许可证文件

安全漏洞