You are here

function twitter_oauth_callback_validate in Twitter 6.3

Same name and namespace in other branches
  1. 6.5 twitter.pages.inc \twitter_oauth_callback_validate()
  2. 6.4 twitter.pages.inc \twitter_oauth_callback_validate()

File

./twitter.pages.inc, line 351

Code

function twitter_oauth_callback_validate($form, &$form_state) {
  $key = variable_get('twitter_consumer_key', '');
  $secret = variable_get('twitter_consumer_secret', '');
  $form_state['twitter_oauth'] = $_SESSION['twitter_oauth'];
  unset($_SESSION['twitter_oauth']);
  $token = $form_state['twitter_oauth']['token'];
  if (!is_array($token) || !$key || !$secret) {
    form_set_error('oauth_token', t('Invalid Twitter OAuth request'));
  }
  if ($token['oauth_token'] != $form_state['values']['oauth_token']) {
    form_set_error('oauth_token', t('Invalid OAuth token.'));
  }
  module_load_include('php', 'oauth_common', 'lib/OAuth');
  module_load_include('inc', 'twitter');
  $twitter = new TwitterOAuth($key, $secret, $token['oauth_token'], $token['oauth_token_secret']);
  $response = $twitter
    ->get_access_token();
  $form_state['twitter_oauth']['response'] = $response;
}