You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
@@ -7,11 +7,12 @@ This example covers sending a batch request with the Facebook SDK for PHP.
7
7
The following example assumes we have the following permissions granted from the user: `user_likes`, `user_events`, `user_photos`, `publish_actions`. The example makes use of [JSONPath to reference specific batch operations](https://developers.facebook.com/docs/graph-api/making-multiple-requests/#operations).
8
8
9
9
```php
10
+
<?php
10
11
$fb = new Facebook\Facebook([
11
-
'app_id' => '{app-id}',
12
-
'app_secret' => '{app-secret}',
13
-
'default_graph_version' => 'v2.8',
14
-
]);
12
+
'app_id' => '{app-id}',
13
+
'app_secret' => '{app-secret}',
14
+
'default_graph_version' => 'v2.8',
15
+
]);
15
16
16
17
// Since all the requests will be sent on behalf of the same user,
17
18
// we'll set the default fallback access token here.
There five requests being made in this batch requests.
@@ -96,48 +98,181 @@ My next 2 events are House Warming Party,Some Foo Event.
96
98
97
99
It should also contain a response containing two photos from the user.
98
100
99
-
> **Warning:** The response object should return a `null` response for any request that was pointed to with JSONPath as is [the behaviour of the batch functionality of the Graph API](https://developers.facebook.com/docs/graph-api/making-multiple-requests/#operations).
101
+
> **Warning:** The response object should return a `null` response for any request that was pointed to with JSONPath as is [the behaviour of the batch functionality of the Graph API](https://developers.facebook.com/docs/graph-api/making-multiple-requests/#operations). If we want to receive the response anyway we have to set the `omit_response_on_success` option to `false`. [See the example below](#force-response-example).
102
+
103
+
## Force Response Example
104
+
105
+
The following example is a subset of the [first example](#example). We will only use the `user-events` and `post-to-feed` requests of the [first example](#example), but in this case we will force the server to return the response of the `user-events` request.
106
+
107
+
```php
108
+
<?php
109
+
$fb = new Facebook\Facebook([
110
+
'app_id' => '{app-id}',
111
+
'app_secret' => '{app-secret}',
112
+
'default_graph_version' => 'v2.8',
113
+
]);
114
+
115
+
// Since all the requests will be sent on behalf of the same user,
116
+
// we'll set the default fallback access token here.
In the following example we will make two requests.
169
+
* One to post a status update on the user's feed
170
+
* and one to receive the last post of the user (which should be the one that we posted with first request).
171
+
172
+
Since we want the second request to be executed after the first one is completed, we have to set the `depends_on` option of the second request to point to the name of the first request. We assume that we have the following options granted from the user: `user_posts`, `publish_actions`.
173
+
174
+
```php
175
+
<?php
176
+
$fb = new Facebook\Facebook([
177
+
'app_id' => '{app-id}',
178
+
'app_secret' => '{app-secret}',
179
+
'default_graph_version' => 'v2.8',
180
+
]);
181
+
182
+
// Since all the requests will be sent on behalf of the same user,
183
+
// we'll set the default fallback access token here.
> **Warning:** The response object should return a `null` response for any request that was pointed to with the `depends_on` option as is [the behaviour of the batch functionality of the Graph API](https://developers.facebook.com/docs/graph-api/making-multiple-requests/#operations). If we want to receive the response anyway we have to set the `omit_response_on_success` option to `false`. [See example](#force-response-example).
100
234
101
235
## Multiple User Example
102
236
103
237
Since the requests sent in a batch are unrelated by default, we can make requests on behalf of multiple users and pages in the same batch request.
Copy file name to clipboardExpand all lines: docs/reference/FacebookBatchRequest.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,8 @@ Represents a batch request that will be sent to the Graph API.
4
4
5
5
## Facebook\FacebookBatchRequest
6
6
7
-
You can instantiate a new `FacebookBatchRequest` entity directly by sending the arguments to the constructor.
7
+
You can instantiate a new `FacebookBatchRequest` entity directly by sending the arguments to the constructor or
8
+
by using the [`Facebook\Facebook::newBatchRequest()`](Facebook.md#newBatchRequest) factory method.
8
9
9
10
```php
10
11
use Facebook\FacebookBatchRequest;
@@ -61,9 +62,9 @@ Since the `Facebook\FacebookBatchRequest` is extended from the [`Facebook\Facebo
61
62
### add()
62
63
```php
63
64
public add(
64
-
array|Facebook\FacebookBatchRequest $request,
65
-
string|null $name
66
-
)
65
+
array|Facebook\FacebookBatchRequest $request,
66
+
string|null $name
67
+
)
67
68
```
68
69
Adds a request to be sent in the batch request. The `$request` can be a single [`Facebook\FacebookRequest`](FacebookRequest.md) or an array of `Facebook\FacebookRequest`'s.
0 commit comments