When user denies access to a twitter account the user is redirected to oauth callback with a GET parameter denied, and since we are always expecting oauth_token in our implementation, and an empty oauth_token parameter throws errors.

    Notice: Undefined index: oauth_token in twitter_oauth_callback() (line 346 of /var/www/html/chia.in/mtweets/sites/all/modules/custom/twitter/twitter.pages.inc).
    Notice: Undefined index: oauth_token in twitter_oauth_callback_form() (line 357 of /var/www/html/chia.in/mtweets/sites/all/modules/custom/twitter/twitter.pages.inc).
    Notice: Undefined index: oauth_token in twitter_oauth_callback_form() (line 360 of /var/www/html/chia.in/mtweets/sites/all/modules/custom/twitter/twitter.pages.inc).
    Invalid OAuth token.
    Notice: Undefined variable: response in TwitterOAuth->get_access_token() (line 367 of /var/www/html/chia.in/mtweets/sites/all/modules/custom/twitter/twitter.lib.php).
    Notice: Undefined index: oauth_token in TwitterOAuth->get_access_token() (line 368 of /var/www/html/chia.in/mtweets/sites/all/modules/custom/twitter/twitter.lib.php).
    Notice: Undefined index: oauth_token_secret in TwitterOAuth->get_access_token() (line 368 of /var/www/html/chia.in/mtweets/sites/all/modules/custom/twitter/twitter.lib.php).

Here is a patch to fix this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

steinmb’s picture

Is this issue related to #1363044: Callback URL Error ? The patch looks fine though we prob. need to polish the English error message.

Josephnewyork’s picture

This needs to be pushed. Here is mine:

function twitter_oauth_callback() {
	if(isset($_GET['denied']) || !isset($_GET['oauth_token'])) {
		drupal_set_message(t('Your connection to twitter.com was denied or canceled. Please try again.'), 'error');
		drupal_goto('<front>');
		return;
	}
  $form_state['values']['oauth_token'] = $_GET['oauth_token'];
  drupal_form_submit('twitter_oauth_callback_form', $form_state);
}
pfrenssen’s picture

Assigned: chia » Unassigned
Status: Active » Needs review
FileSize
990 bytes

I combined the patches from chia and Joe Weitzel, rerolled to the latest dev and added some small improvements.

juampynr’s picture

Status: Needs review » Fixed

Outstanding work here guys. Many thanks. This has been committed.

http://drupalcode.org/project/twitter.git/commitdiff/741521a

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

xurizaemon’s picture

Status: Closed (fixed) » Fixed

Committing a slight improvement in ae75024 and 0a46516, so that if you're logged in and trying to associate a Twitter account, you are returned to user/%/edit/twitter instead of <front>.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rajiv.singh’s picture

Issue summary: View changes

Hi @xurizaemon ,
Which version has commits ae75024 and 0a46516 .
I am using 7.x-5.8 and can see following code

/**
 * Wrapper to call drupal_form_submit() which wasn't required in D6.
 */
function twitter_oauth_callback() {
  if (isset($_GET['denied']) || empty($_GET['oauth_token'])) {
    drupal_set_message(t('The connection to Twitter failed. Please try again.'), 'error');
    global $user;
    if ($user->uid) {
      // User is logged in, was attempting to OAuth a Twitter account.
      drupal_goto('admin/config/services/twitter');
    }
    else {
      // Anonymous user, redirect to front page.
      drupal_goto('<front>');
    }
  }
  $form_state['values']['oauth_token'] = $_GET['oauth_token'];
  drupal_form_submit('twitter_oauth_callback_form', $form_state);
}