You are here

public function SocialContentLinkedin::getAccessToken in Social Content 7.2

Get access token from Linkedin.

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 SocialContentLinkedin::getAccessToken()
SocialContentLinkedin::globalSettingsForm in modules/linkedin/social_content_linkedin.class.inc
The shared global settings form for all Linkedin instances.

File

modules/linkedin/social_content_linkedin.class.inc, line 307
Social Content Linkedin class.

Class

SocialContentLinkedin
@file Social Content Linkedin class.

Code

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