You are here

function fb_api_batch in Drupal for Facebook 6.3

Same name and namespace in other branches
  1. 7.3 fb.module \fb_api_batch()

Helper function for facebook's batch graph api.

This function accepts a simpler interface than facebook's. The queries are passed in as a simple array, and the data is parsed into a PHP data structure.

@TODO: when $method=='GET', share caching with fb_api().

File

./fb.module, line 699
This is the core required module of Drupal for Facebook.

Code

function fb_api_batch($fb, $queries, $params, $method = 'GET') {
  $data = array();

  // Build facebook's data structure.  Our's supports only GET or POST at a time.
  $fb_queries = array();
  foreach ($queries as $query) {
    $fb_queries[] = array(
      'method' => $method,
      'relative_url' => $query,
    );
  }
  $wrapped_data = $fb
    ->api('/?batch=' . json_encode($fb_queries), 'POST', $params);

  // Use POST, not $method.
  foreach ($wrapped_data as $w_d) {
    if ($w_d['code'] == 200 && isset($w_d['body'])) {
      $data[] = json_decode($w_d['body'], TRUE);
    }
    else {

      // Unexpected code
      $data[] = $w_d;
    }
  }
  return $data;
}