Mercurial > nebulaweb3
comparison default/assets/vendors/theme-widgets/vendor/mute/facebook/README.rst @ 0:1d038bc9b3d2 default tip
Up:default
author | Liny <dev@neowd.com> |
---|---|
date | Sat, 31 May 2025 09:21:51 +0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1d038bc9b3d2 |
---|---|
1 Mute Facebook | |
2 ============= | |
3 | |
4 | |
5 Implements `Graph API`_ and some of the OAuth facilities to operate with Facebook. See `examples`_ for usage. | |
6 | |
7 This library package requires `PHP 5.3`_ or later. | |
8 | |
9 | |
10 How to use this library | |
11 ----------------------- | |
12 | |
13 Simple requests:: | |
14 | |
15 <?php | |
16 | |
17 $app = new \Mute\Facebook\App(APP_ID, APP_SECRET, APP_NAMESPACE); | |
18 | |
19 // get name of a user | |
20 $response = $app->get(USER_ID, array('fields' => 'name')); | |
21 echo "user's name is " . $response['name']; | |
22 | |
23 // or the full response | |
24 $response = $app->get(USER_ID, array('fields' => 'name'), null, true); | |
25 echo "user's name is " . $response['body']['name']; | |
26 | |
27 // post a photo | |
28 $response = $app->post(USER_ID . '/photo', null, array( | |
29 'source' => PHOTO_FILENAME | |
30 )); | |
31 | |
32 // get the fresh list friends | |
33 $response = $app->get(USER_ID . '/friends', null, null, array( | |
34 'If-None-Match: ' . PREVIOUS_ETAG, | |
35 )); | |
36 | |
37 By default, app access token will be automatically append. If you need to request with a custom access_token:: | |
38 | |
39 <?php | |
40 $data = $app->get('me', array( | |
41 'access_token' => MY_ACCESS_TOKEN, | |
42 )); | |
43 // or | |
44 $customApp = $app->getAuthenticatedGraphApi(MY_ACCESS_TOKEN); | |
45 $data = $customApp->get('me'); | |
46 | |
47 Batched requests:: | |
48 | |
49 <?php | |
50 // only bodies | |
51 $responses = $customApp->batch() | |
52 ->get('me') | |
53 ->get('me/friends', array('limit' => 50)) | |
54 ->execute(); | |
55 // or | |
56 $responses = $customApp->batch(function($app) { | |
57 $app->get('me'); | |
58 $app->get('me/friends', array('limit' => 50)); | |
59 }); | |
60 | |
61 // for full responses, you can do | |
62 $responses = $customApp->getAuthenticatedGraphApi(MY_ACCESS_TOKEN)->batch() | |
63 ->get('me') | |
64 ->get('me/friends', array('limit' => 50)) | |
65 ->execute(true); | |
66 // or | |
67 $responses = $customApp->batch(function($customApp) { | |
68 $customApp->get('me'); | |
69 $customApp->get('me/friends', array('limit' => 50)); | |
70 }, true); | |
71 | |
72 Sometimes you need more control of the http request. for this you can manipulate the options:: | |
73 | |
74 <?php | |
75 // fetching a paginated list of friends can very long, set up the timeout to 30 seconds | |
76 $app->setOptions('timeout', 60); | |
77 $friends = $app->get(USER_ID . '/friends', array( | |
78 'offset' => 5000, | |
79 'limit' => 5000, | |
80 )); | |
81 // once finished, you can reset the options | |
82 $app->resetOptions(); | |
83 | |
84 Api will hit default graph api version. You may change version:: | |
85 | |
86 <?php | |
87 $app = $app->changeVersion('v2.0'); | |
88 | |
89 | |
90 More | |
91 ---- | |
92 | |
93 For generating the API doc, install apigen_, and then run:: | |
94 | |
95 $ apigen -c apigen.neon | |
96 | |
97 For running unittests, install PHPUnit_, and then run:: | |
98 | |
99 $ phpunit -c tests/phpunit.xml | |
100 | |
101 | |
102 .. _Graph API: https://developers.facebook.com/docs/reference/api/ | |
103 .. _examples: https://github.com/johnnoone/php-facebook/tree/master/example | |
104 .. _PHP 5.3: http://php.net/releases/5_3_0.php | |
105 .. _apigen: apigen.org | |
106 .. _PHPUnit: www.phpunit.de |