33[ ![ Build Status] ( https://github.com/nickdnk/php-graph-sdk/actions/workflows/test.yml/badge.svg?branch=master )] ( https://github.com/nickdnk/php-graph-sdk/actions/workflows/test.yml )
44[ ![ Latest Stable Version] ( http://img.shields.io/badge/Latest%20Stable-7.0.1-blue.svg )] ( https://packagist.org/packages/nickdnk/graph-sdk )
55[ ![ Downloads] ( https://img.shields.io/packagist/dt/nickdnk/graph-sdk?label=Downloads )] ( https://packagist.org/packages/nickdnk/graph-sdk )
6- ### This is an unofficial version of Facebook's PHP SDK designed for PHP 7/ 8+. It is being maintained and tested against the newest PHP versions. You can use this in place of version ` 5.x ` of Facebook's deprecated ` facebook/graph-sdk ` package.
6+ ### This is an unofficial version of Facebook's PHP SDK designed for PHP 8+. It is being maintained and tested against the newest PHP versions. You can use this in place of version ` 5.x ` of Facebook's deprecated ` facebook/graph-sdk ` package.
77
8- ## PHP 7.3 is required.
8+ ### PHP 8.1 is required.
99
1010This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app.
1111
@@ -20,7 +20,7 @@ composer require nickdnk/graph-sdk
2020By default, the request will be made via a ` Facebook\HttpClients\FacebookHttpClientInterface ` . The default
2121implementation depends on the available PHP extension/packages. In order of priority:
2222
23- 1 . Package ` guzzlehttp/guzzle ` (version 6 or 7 ): ` Facebook\HttpClients\FacebookGuzzleHttpClient `
23+ 1 . Package ` guzzlehttp/guzzle ` (v6 and v7 only ): ` Facebook\HttpClients\FacebookGuzzleHttpClient `
24242 . ext-curl: ` Facebook\HttpClients\FacebookCurlHttpClient `
25253 . Fallback: ` Facebook\HttpClients\FacebookStreamHttpClient `
2626
@@ -29,12 +29,17 @@ implementation depends on the available PHP extension/packages. In order of prio
2929Simple GET example of a user's profile.
3030
3131``` php
32- require_once __DIR__ . '/vendor/autoload.php'; // change path as needed
32+ require_once __DIR__ . '/vendor/autoload.php';
3333
34- $fb = new \Facebook\Facebook([
34+ use Facebook\Facebook;
35+ use Facebook\GraphNodes\GraphUser;
36+ use Facebook\Exceptions\FacebookResponseException;
37+ use Facebook\Exceptions\FacebookSDKException;
38+
39+ $fb = new Facebook([
3540 'app_id' => '{app-id}',
3641 'app_secret' => '{app-secret}',
37- 'default_graph_version' => 'v2.10 ',
42+ 'default_graph_version' => 'v20.0 ',
3843 //'default_access_token' => '{access-token}', // optional
3944]);
4045
@@ -45,45 +50,41 @@ $fb = new \Facebook\Facebook([
4550// $helper = $fb->getPageTabHelper();
4651
4752try {
48- // Get the \Facebook\GraphNodes\GraphUser object for the current user.
53+
4954 // If you provided a 'default_access_token', the '{access-token}' is optional.
5055 $response = $fb->get('/me', '{access-token}');
51- } catch(\Facebook\Exceptions\FacebookResponseException $e) {
56+
57+ // To decode the response to a PHP class, provide the class of the root node in the response. You will have to match
58+ // this manually based on the endpoint you requested. Please do open a pull request if you want to add more types.
59+
60+ /** @var GraphUser $me */
61+ $me = $response->getGraphNode(GraphUser::class);
62+ echo 'Logged in as ' . $me->getName() . PHP_EOL;
63+ echo 'User email is ' . $me->getEmail() . PHP_EOL;
64+
65+ } catch (FacebookResponseException $e) {
66+
5267 // When Graph returns an error
5368 echo 'Graph returned an error: ' . $e->getMessage();
54- exit;
55- } catch(\Facebook\Exceptions\FacebookSDKException $e) {
69+
70+ } catch (FacebookSDKException $e) {
71+
5672 // When validation fails or other local issues
5773 echo 'Facebook SDK returned an error: ' . $e->getMessage();
58- exit;
74+
5975}
60-
61- $me = $response->getGraphUser();
62- echo 'Logged in as ' . $me->getName();
6376```
6477
65- Complete documentation, installation instructions, and examples are available [ here] ( docs/ ) .
66-
6778## Tests
6879
69801 . [ Composer] ( https://getcomposer.org/ ) is a prerequisite for running the tests. Install composer globally, then
7081 run ` composer install ` to install required files.
71- 2 . Create a test app on [ Facebook Developers] ( https://developers.facebook.com ) , then
72- create ` tests/FacebookTestCredentials.php ` from ` tests/FacebookTestCredentials.php.dist ` and edit it to add your
73- credentials.
74- 3 . The tests can be executed by running this command from the root directory:
82+ 2 . The tests can be executed by running this command from the root directory:
7583
7684``` bash
7785$ ./vendor/bin/phpunit
7886```
7987
80- By default, the tests will send live HTTP requests to the Graph API. If you are without an internet connection you can
81- skip these tests by excluding the ` integration ` group.
82-
83- ``` bash
84- $ ./vendor/bin/phpunit --exclude-group integration
85- ```
86-
8788## License
8889
8990Please see the [ license file] ( https://github.com/facebook/php-graph-sdk/blob/master/LICENSE ) for more information.
0 commit comments