You are here

protected function SocialFacebookFormatter::getAccessToken in Open Social 7

Get access token.

Return value

string String containing access token.

1 call to SocialFacebookFormatter::getAccessToken()
SocialFacebookFormatter::getData in includes/social_comments.facebook.inc

File

includes/social_comments.facebook.inc, line 38
Facebook class

Class

SocialFacebookFormatter
@file Facebook class

Code

protected function getAccessToken() {

  // Set cache key.
  $cache_key = 'social_comments:facebook_access_token';
  $token = NULL;

  // Try to get comments from cache.
  if ($cache = cache_get($cache_key)) {
    $token = $cache->data;
  }
  else {
    $response_url = url('https://graph.facebook.com/oauth/access_token', array(
      'query' => array(
        'client_id' => $this->app_id,
        'client_secret' => $this->app_secret,
        'grant_type' => 'client_credentials',
      ),
    ));
    $data = drupal_http_request($response_url);
    if ($data->code != 200) {
      watchdog('social_comments', $data->error, array(), WATCHDOG_WARNING);
      return FALSE;
    }
    if ($data->data && strpos($data->data, 'access_token') === 0) {
      $token = drupal_substr($data->data, 13);

      // Set data to cache.
      cache_set($cache_key, $token);
    }
  }
  return $token;
}