You are here

function twitter_oauth_callback_form_submit in Twitter 7.4

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.5 twitter.pages.inc \twitter_oauth_callback_form_submit()

Handle a Twitter OAuth return request and store the account creds in the DB. Redirects to user/%/edit/twitter

File

./twitter.pages.inc, line 444
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;
  }
  $twitter_account
    ->set_auth($response);
  $account = $form_state['twitter_oauth']['account'];
  twitter_account_save($twitter_account, TRUE, $account);
  $form_state['programmed'] = FALSE;
  $form_state['redirect'] = $form_state['twitter_oauth']['destination'];
}