You are here

function fboauth_graph_query in Facebook OAuth (FBOAuth) 7

Same name and namespace in other branches
  1. 6 includes/fboauth.fboauth.inc \fboauth_graph_query()
  2. 7.2 includes/fboauth.fboauth.inc \fboauth_graph_query()

Execute a Graph API query through Facebook.

See also

http://developers.facebook.com/docs/reference/api/

2 calls to fboauth_graph_query()
fboauth_action_connect in includes/fboauth.fboauth.inc
Facebook OAuth callback for initiating a Facebook connection.
fboauth_field_convert_image in includes/fboauth.field.inc
Facebook data conversion function.

File

includes/fboauth.fboauth.inc, line 831
Provides functions used during Facebook login processes.

Code

function fboauth_graph_query($id, $access_token = NULL, $parameters = array(), $method = 'GET') {
  if (isset($access_token)) {
    $parameters['access_token'] = $access_token;
  }
  if ($method == 'GET' || $method == 'DELETE') {
    $graph_url = url('https://graph.facebook.com/v2.2/' . $id, array(
      'absolute' => TRUE,
      'query' => $parameters,
    ));
    $graph_result = drupal_http_request($graph_url, array(
      'headers' => array(),
      'method' => $method,
    ));
  }
  elseif ($method == 'POST') {
    $graph_url = 'https://graph.facebook.com/v2.2/' . $id;
    $post_data = http_build_query($parameters, '', '&');
    $graph_result = drupal_http_request($graph_url, array(
      'headers' => array(),
      'method' => $method,
      'data' => $post_data,
    ));
  }
  else {
    drupal_set_message(t('Invalid request type "@type" for Facebook graphy query. Must be either @get, @post, or @delete.', array(
      '@type' => $method,
      '@get' => 'GET',
      '@post' => 'POST',
      '@delete' => 'DELETE',
    )), 'error');
  }

  // If the response contains a redirect (such as to an image), return the
  // redirect as the data. i.e. https://graph.facebook.com/v2.2/19292868552/picture.
  if (isset($graph_result->redirect_url)) {
    $data = array(
      'data' => $graph_result->data,
      'redirect_code' => $graph_result->redirect_code,
      'redirect_url' => $graph_result->redirect_url,
    );
  }
  else {
    $data = json_decode($graph_result->data);
  }
  return $data;
}