You are here

function twitter_oauth_callback_form_submit in Twitter 7.5

Same name and namespace in other branches
  1. 7.6 twitter.pages.inc \twitter_oauth_callback_form_submit()
  2. 7.3 twitter.pages.inc \twitter_oauth_callback_form_submit()
  3. 7.4 twitter.pages.inc \twitter_oauth_callback_form_submit()

Handle a Twitter OAuth return request and store the account creds in the DB.

File

./twitter.pages.inc, line 507
Page callbacks for Twitter module.

Code

function twitter_oauth_callback_form_submit($form, &$form_state) {
  $key = variable_get('twitter_consumer_key', '');
  $secret = variable_get('twitter_consumer_secret', '');
  $response = $form_state['twitter_oauth']['response'];
  $twitter = new Twitter($key, $secret, $response['oauth_token'], $response['oauth_token_secret']);
  try {
    $twitter_account = $twitter
      ->users_show($response['screen_name']);
  } catch (TwitterException $e) {
    form_set_error('screen_name', t('Request failed: @message.', array(
      '@message' => $e
        ->getMessage(),
    )));
    return;
  }

  // Save the new Twitter account and set the user's uid who added it.
  $twitter_account
    ->set_auth($response);
  global $user;
  $twitter_account->uid = $user->uid;
  twitter_account_save($twitter_account, TRUE);
  $form_state['programmed'] = FALSE;
  $form_state['redirect'] = $form_state['twitter_oauth']['destination'];
}