function fb_graph_batch in Drupal for Facebook 7.4
Read from facebook's graph in batch mode. Allows a single request to facebook to return data from multiple graph nodes.
Only GET currently supported.
Parameters
$paths: An array containing one or more graph paths.
$params: The access token to use for this request.
$options: TODO: cache control.
Return value
Returns an array where each key is one of the paths passed in. The Values are the graph information for that path.
11 calls to fb_graph_batch()
- fb_admin_add_token_form in ./
fb.admin.inc - fb_admin_add_token_form_validate in ./
fb.admin.inc - fb_admin_token_generate_validate in ./
fb.admin.inc - fb_admin_token_info in ./
fb.admin.inc - Display detailed information about a token.
- fb_admin_token_page in ./
fb.admin.inc
File
- ./
fb.module, line 1329
Code
function fb_graph_batch($paths, $params = NULL, $options = array(), &$errors = NULL) {
if (isset($params['access_token']) && !$params['access_token'] && function_exists('debugger')) {
debugger();
}
// Accept either params array or access token, for caller's convenience.
if (is_array($params)) {
$token = !empty($params['access_token']) ? $params['access_token'] : FALSE;
}
elseif (is_string($params)) {
$token = $params;
$params = array(
'access_token' => $token,
);
}
elseif ($params === NULL) {
$token = NULL;
$params = array(
'access_token' => fb_access_token(),
);
}
foreach ($paths as $path) {
// Accept either array or path string, for caller's convenience.
if (is_string($path)) {
$path_array[] = array(
'method' => 'GET',
'relative_url' => $path,
);
}
else {
$path_array[] = $path + array(
// defaults
'method' => 'GET',
);
}
}
$params['batch'] = json_encode($path_array);
$url = url("https://graph.facebook.com/", array(
'query' => $params,
));
$result = fb_http($url, array(
'method' => 'POST',
));
// Put the result into an easy to work with format.
foreach ($paths as $i => $path) {
if (is_array($path)) {
$path = $path['relative_url'];
}
try {
$return[$path] = fb_http_parse_response($result[$i]);
} catch (exception $e) {
// If caller passed in $errors array, store the error. Otherwise fail loudly.
if (!isset($errors)) {
fb_log_exception($e, t('Batch query %path failed.', array(
'%path' => $path,
)));
throw $e;
}
else {
$errors[$path] = $e;
}
}
}
return $return;
}