3
3
[ ![ 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 )
4
4
[ ![ Latest Stable Version] ( http://img.shields.io/badge/Latest%20Stable-7.0.1-blue.svg )] ( https://packagist.org/packages/nickdnk/graph-sdk )
5
5
[ ![ 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.
7
7
8
- ## PHP 7.3 is required.
8
+ ### PHP 8.1 is required.
9
9
10
10
This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app.
11
11
@@ -20,7 +20,7 @@ composer require nickdnk/graph-sdk
20
20
By default, the request will be made via a ` Facebook\HttpClients\FacebookHttpClientInterface ` . The default
21
21
implementation depends on the available PHP extension/packages. In order of priority:
22
22
23
- 1 . Package ` guzzlehttp/guzzle ` (version 6 or 7 ): ` Facebook\HttpClients\FacebookGuzzleHttpClient `
23
+ 1 . Package ` guzzlehttp/guzzle ` (v6 and v7 only ): ` Facebook\HttpClients\FacebookGuzzleHttpClient `
24
24
2 . ext-curl: ` Facebook\HttpClients\FacebookCurlHttpClient `
25
25
3 . Fallback: ` Facebook\HttpClients\FacebookStreamHttpClient `
26
26
@@ -29,12 +29,17 @@ implementation depends on the available PHP extension/packages. In order of prio
29
29
Simple GET example of a user's profile.
30
30
31
31
``` php
32
- require_once __DIR__ . '/vendor/autoload.php'; // change path as needed
32
+ require_once __DIR__ . '/vendor/autoload.php';
33
33
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([
35
40
'app_id' => '{app-id}',
36
41
'app_secret' => '{app-secret}',
37
- 'default_graph_version' => 'v2.10 ',
42
+ 'default_graph_version' => 'v20.0 ',
38
43
//'default_access_token' => '{access-token}', // optional
39
44
]);
40
45
@@ -45,45 +50,41 @@ $fb = new \Facebook\Facebook([
45
50
// $helper = $fb->getPageTabHelper();
46
51
47
52
try {
48
- // Get the \Facebook\GraphNodes\GraphUser object for the current user.
53
+
49
54
// If you provided a 'default_access_token', the '{access-token}' is optional.
50
55
$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
+
52
67
// When Graph returns an error
53
68
echo 'Graph returned an error: ' . $e->getMessage();
54
- exit;
55
- } catch(\Facebook\Exceptions\FacebookSDKException $e) {
69
+
70
+ } catch (FacebookSDKException $e) {
71
+
56
72
// When validation fails or other local issues
57
73
echo 'Facebook SDK returned an error: ' . $e->getMessage();
58
- exit;
74
+
59
75
}
60
-
61
- $me = $response->getGraphUser();
62
- echo 'Logged in as ' . $me->getName();
63
76
```
64
77
65
- Complete documentation, installation instructions, and examples are available [ here] ( docs/ ) .
66
-
67
78
## Tests
68
79
69
80
1 . [ Composer] ( https://getcomposer.org/ ) is a prerequisite for running the tests. Install composer globally, then
70
81
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:
75
83
76
84
``` bash
77
85
$ ./vendor/bin/phpunit
78
86
```
79
87
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
-
87
88
## License
88
89
89
90
Please see the [ license file] ( https://github.com/facebook/php-graph-sdk/blob/master/LICENSE ) for more information.
0 commit comments