You are here

function _facebook_pull_accesstoken in Facebook Pull 7.3

Same name and namespace in other branches
  1. 6 facebook_pull.module \_facebook_pull_accesstoken()
  2. 7 facebook_pull.module \_facebook_pull_accesstoken()
  3. 7.2 facebook_pull.module \_facebook_pull_accesstoken()

Get an access token.

1 call to _facebook_pull_accesstoken()
_facebook_pull_feed_cached in ./facebook_pull.module
Pull data from a facebook feed and cache it.

File

./facebook_pull.module, line 307
Facebook Pull Module for getting content from Facebook graph.

Code

function _facebook_pull_accesstoken($app_id, $app_secret) {
  $endpoint = 'https://graph.facebook.com/oauth/access_token?client_id=%s&client_secret=%s&grant_type=client_credentials';
  $full_url = sprintf($endpoint, $app_id, $app_secret);
  $token = drupal_http_request($full_url);
  $token = $token->data;
  if (!$token) {
    $message = 'Failed to fetch data from the Facebook Graph';
    $variables = array();
    watchdog('facebook_pull', $message, $variables, WATCHDOG_WARNING);
    return FALSE;
  }
  $token = json_decode($token, TRUE);
  if (json_last_error() !== JSON_ERROR_NONE) {
    $message = 'Facebook Graph authentication response invalid.';
    watchdog('facebook_pull', $message, array(), WATCHDOG_WARNING);
    return FALSE;
  }
  if (!isset($token['access_token'])) {
    $message = 'Facebook Graph failed to provide access token.';
    watchdog('facebook_pull', $message, array(), WATCHDOG_WARNING);
    return FALSE;
  }
  return http_build_query($token);
}