function fb_graph in Drupal for Facebook 7.3
Same name and namespace in other branches
- 6.3 fb.module \fb_graph()
- 7.4 fb.module \fb_graph()
Helper function to work with facebook "open" graph.
18 calls to fb_graph()
- fb_admin_app_page in ./
fb.admin.inc - fb_admin_get_app_info in ./
fb.admin.inc - fb_admin_set_properties_form_submit in ./
fb.admin.inc - Confirm form submit function. We don't use fb_app_set_app_properties, because fb_app.module may not be enabled.
- fb_app_fb_admin in ./
fb_app.admin.inc - Implements hook_fb_admin().
- fb_app_set_app_properties in ./
fb_app.admin.inc - Sets callback URLs and other properties of a facebook app. Calls the facebook
1 string reference to 'fb_graph'
- fb_graph_publish_action in ./
fb_graph.module - Helper function to publish user activity to Facebook's Open Graph.
File
- ./
fb.module, line 572 - This is the core required module of Drupal for Facebook.
Code
function fb_graph($path, $params = array(), $method = 'GET', $fb = NULL) {
if (!$fb) {
$fb = $GLOBALS['_fb'];
}
if ($method == 'GET') {
$url = url("https://graph.facebook.com/{$path}", array(
'query' => $params,
));
$http = drupal_http_request($url);
}
else {
$url = "https://graph.facebook.com/{$path}";
$headers = array();
//$headers = array('Content-Type' => 'application/x-www-form-urlencoded'); // Needed??
$query = http_build_query($params, '', '&');
$http = drupal_http_request($url, array(
'headers' => $headers,
'method' => $method,
'data' => $query,
));
}
if (isset($http->data)) {
$data = json_decode($http->data, TRUE);
// Most times graph returns JSON, but other times query string. Thanks Facebook!
if (!$data) {
parse_str($http->data, $data);
}
}
else {
$data = array();
// avoid php warnings.
}
if (!isset($http->error) && !empty($data)) {
if (is_array($data)) {
if (isset($data['error_code'])) {
throw new FacebookApiException($data);
}
}
elseif ($http->data == 'true' || $http->code == 200) {
// No problems.
}
else {
// Never reach this???
if (function_exists('dpm')) {
dpm($http, __FUNCTION__ . " unexpected result from {$url}");
}
// XXX
}
return $data;
}
elseif (!empty($data)) {
// Error has a message.
// TODO: parse error code from message.
$message = t('fb_graph failed querying !path. !type: !detail', array(
'!path' => $path,
'!type' => $data['error']['type'],
'!detail' => $data['error']['message'],
));
throw new Exception($message);
// Do we need our own code???
}
else {
$data = json_decode($http->data, TRUE);
$message = t('fb_graph failed querying !path. !detail', array(
'!path' => $path,
'!detail' => $http->error,
));
throw new Exception($message);
// Do we need our own code???
}
}