The fboauth_graph_query() function defined in the fboauth module supports only GET requests. A lot of features that I need to implement for the site I am working on require me to make requests that the fb api documentation clearly says can only be done using POST requests.
I came up with a replacement to the function that I use and it works well. I thought I'd share it here so it may be included in the fboauth module.
The function can be called exactly as fboauth_graph_query(). One need only specify the type of request if POST type is required.

/*
 * Copy of fboauth_graph_query with ability to select type of request POST or GET.
 * Because updating fb pages etc. can only be done using POST requests and the fboauth_graph_query func doesn't support POST.
*/
function mymodule_graph_query($id, $access_token, $parameters = array(), $method = 'GET') {
  $parameters['access_token'] = $access_token;

  if ( $method == 'GET') {
    $graph_url = url('https://graph.facebook.com/' . $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/' . $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('error', 'Invalid request type provided for mymodule_graph_query()');
  }
  return json_decode($graph_result->data);
}

Comments

v-a-1’s picture

Sorry. The drupal_set_message line is incorrect. It should be:
drupal_set_message('Invalid request type provided for mymodule_graph_query()', 'error');

quicksketch’s picture

Thanks for your suggestion! If you can post this as a patch I'll look at it next time I'm working on FBOAuth.

quicksketch’s picture

Status: Active » Fixed
StatusFileSize
new1.38 KB

I've committed this patch to both branches of FBOAuth.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

v-a-1’s picture

Status: Closed (fixed) » Active
StatusFileSize
new747 bytes

I've recently discovered that some Facebook requests use the HTTP 'DELETE' verb.
e.g. https://developers.facebook.com/docs/reference/api/page/ (Look under sections titled Delete).
And so have updated the fboauth_graph_query() to reflect the same.
Find attached a patch.

Note: I haven't come across the PUT method anywhere in the Facebook API, and I don't think it will ever be used, considering POST is generally used in its place. So I don't think support for PUT is required.

v-a-1’s picture

Status: Active » Needs review
quicksketch’s picture

Thanks! Committed after fixing a minor error text. Here a backport for D6 too.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.