You are here

function fb_graph in Drupal for Facebook 6.3

Same name and namespace in other branches
  1. 7.4 fb.module \fb_graph()
  2. 7.3 fb.module \fb_graph()

Helper function to work with facebook "open" graph.

15 calls to fb_graph()
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
Implementation of 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
fb_graph_delete_confirm_form in ./fb_graph.pages.inc
Form creator -- ask for confirmation of deletion

... See full list

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 484
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, $headers, $method, $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???
  }
}