viktorruskai / facebook-graph-sdk
PHP Facebook SDK
6.0.2
2022-07-13 13:34 UTC
Requires
- php: ^8.0|^8.1
Requires (Dev)
- ext-curl: *
- ext-mbstring: *
- guzzlehttp/guzzle: ~7.0
- mockery/mockery: ~1.5
- phpstan/phpstan: 1.6.x-dev
- phpunit/phpunit: ~9.0
- 6.0.2
- 6.0.1
- 6.0.0.x-dev
- 6.0.0
- dev-master / 5.x-dev
- 5.7.0
- 5.6.3
- 5.6.2
- 5.6.1
- 5.6.0
- 5.5.x-dev
- 5.5.0
- 5.4.4
- 5.4.3
- 5.4.2
- 5.4.1
- 5.4.0
- 5.3.1
- 5.3.0
- 5.2.1
- 5.2.0
- 5.1.5
- 5.1.4
- 5.1.3
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.0
- 4.0.23
- 4.0.22
- 4.0.21
- 4.0.20
- 4.0.19
- 4.0.18
- 4.0.17
- 4.0.16
- 4.0.15
- 4.0.14
- 4.0.13
- 4.0.12
- 4.0.11
- 4.0.10
- 4.0.9
- 4.0.8
- 4.0.7
- 4.0.6
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- v4.0.0
- dev-feature/add-phpstan
This package is auto-updated.
Last update: 2024-09-13 18:29:56 UTC
README
此存储库是从原始包分叉的。它已被重构以处理PHP 8.0和PHP 8.1。
安装
可以使用Composer安装Facebook PHP SDK。运行此命令
$ composer require viktorruskai/facebook-graph-sdk
用法
注意:此版本的Facebook SDK for PHP需要PHP 5.4或更高版本。
用户个人资料简单GET示例。
$fb = new \Facebook\Facebook([ '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();
完整文档、安装说明和示例可在此处找到。
测试
可以从根目录运行此命令来执行测试
注意:您可以在Facebook Developers上创建测试应用,然后从
tests/FacebookTestCredentials.php.dist
创建tests/FacebookTestCredentials.php
并编辑它以添加您的凭据。
$ composer tests
默认情况下,测试将向Graph API发送实时HTTP请求。如果您没有网络连接,可以通过排除integration
组来跳过这些测试。
$ composer tests-without-http-requests
贡献
为了使我们能够接受贡献,您首先必须签署贡献者许可协议。请参阅CONTRIBUTING以获取详细信息。
许可
请参阅许可文件以获取更多信息。