Designing my first app against the Graph API, using version 2.1.2 of the Facebook supplied PHP library. Trying to maximize performance, etc out of the box and want to batch a few calls together into one call, but can't find anything in the documentation... I am sure I must be missing something simple, but am stumped.
I'd like to turn these calls (just an example) into a single batched call:
$me = $facebook->api('/me', $params);
$groups = $facebook->api('/me/groups', $params);
Graph API Version Deprecations: August 3, 2021: Graph API v3. 3 will be deprecated and removed from the platform. November 2, 2021: Graph API v4. 0 will be deprecated and removed from the platform.
Individual requests can be executed in a specified order by using the dependsOn property. This property is an array of strings that references the id of a different individual request.
As you suggested, the Graph API, just like the Legacy REST API, is in fact a RESTful API.
A batch request is a single standard HTTP request containing multiple Google Classroom API calls, using the multipart/mixed content type. Within that main HTTP request, each of the parts contains a nested HTTP request. Each part begins with its own Content-Type: application/http HTTP header.
Just an update for the new graph Batch API: You can also execute that as follows:
// Save your method calls into an array
$queries = array(
array('method' => 'GET', 'relative_url' => '/me'),
array('method' => 'GET', 'relative_url' => '/me/groups')
);
// POST your queries to the batch endpoint on the graph.
$batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
// Return values are indexed in order of the original array, content is in ['body'] as a JSON
// string. Decode for use as a PHP array.
$user_profile = json_decode($batchResponse[0]['body'], true);
$user_groups = json_decode($batchResponse[1]['body'], true);
That should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With