You are here

public function SocialContentInstagram::getAccessToken in Social Content 7.2

Get access token from Instagram.

Parameters

array $settings: Settings used to get access token.

string $code: Code from the authorize request.

Return value

string|NULL The token code, or NULL on error.

1 call to SocialContentInstagram::getAccessToken()
SocialContentInstagram::globalSettingsForm in modules/instagram/social_content_instagram.class.inc
The shared global settings form for all Instagram instances.

File

modules/instagram/social_content_instagram.class.inc, line 444
Social Content Instagram class.

Class

SocialContentInstagram
@file Social Content Instagram class.

Code

public function getAccessToken($settings, $code) {
  $fields = array(
    'client_id' => $settings['client_id'],
    'client_secret' => $settings['client_secret'],
    'grant_type' => 'authorization_code',
    'redirect_uri' => url($settings['redirect_uri'], array(
      'query' => array(
        drupal_get_destination(),
      ),
      'absolute' => TRUE,
    )),
    'code' => $code,
  );
  $result = drupal_http_request($settings['api_url'] . '/oauth/access_token', array(
    'method' => 'POST',
    'headers' => array(
      'Content-Type' => 'application/x-www-form-urlencoded',
    ),
    'data' => drupal_http_build_query($fields),
  ));
  $data = json_decode($result->data);
  if ($result->code != 200) {
    drupal_set_message(t('Error: @error', array(
      '@error' => $result->data,
    )), 'error');
    return NULL;
  }
  else {
    return $data->access_token;
  }
}