Using Facebook API for Batch Requests

| | 1 min read

Using Facebook API we can pass instructions for several operations in a single HTTP request. Facebook API process operations as sequentially if it is dependent otherwise it will process as parallel. After completing all the operation it will send a consolidate response to you.

Now we can look on to the simple example

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
$session = new FacebookSession('facebook_access_token');
try {
  $response = (new FacebookRequest($session, 'GET', '/me'))->execute();
  $params = [
      "method"  => "GET",
      "relative_url"  => "/me/groups"

      "method"  => "GET",
      "relative_url"  => "me/likes"
  $response = (new FacebookRequest($session, 'POST', '?batch='.json_encode($params) ))->execute();
  $objects = $response->getGraphObject();
  foreach($objects->asArray() as $object){
    $response_body = json_decode($object->body, 1);
} catch(FacebookRequestException $e) {


Facebook limit the number of requests is 50 in each batch. Please feel free to share your thoughts and doubts regarding thishere.