Hi, I have drupal 7.14 on my site, twitter 7.x-4.1 and oauth 7.x-3.0.
Everytime I try to do any action towards https://api.twitter.com (e.g. Add account, sign in, post tweets) I get the following exception on Drupal log, and nothing works :

exception 'TwitterException' with message 'Unauthorized' in /membri/iartist/portale/sites/all/libraries/twitter/twitter.lib.php:135 Stack trace: #0 /membri/iartist/portale/sites/all/libraries/twitter/twitter.lib.php(98): Twitter->request('https://api.twi...') #1 /membri/iartist/portale/sites/all/libraries/twitter/twitter.lib.php(51): Twitter->auth_request('https://api.twi...', Array) #2 /membri/iartist/portale/sites/all/modules/twitter/twitter.pages.inc(332): Twitter->get_request_token() #3 /membri/iartist/portale/includes/form.inc(1443): twitter_account_form_submit(Array, Array) #4 /membri/iartist/portale/includes/form.inc(854): form_execute_handlers('submit', Array, Array) #5 /membri/iartist/portale/includes/form.inc(374): drupal_process_form('twitter_account...', Array, Array) #6 /membri/iartist/portale/includes/form.inc(131): drupal_build_form('twitter_account...', Array) #7 /membri/iartist/portale/sites/all/modules/twitter/twitter.pages.inc(92): drupal_get_form('twitter_account...', Object(stdClass)) #8 [internal function]: twitter_user_settings(Object(stdClass)) #9 /membri/iartist/portale/includes/menu.inc(516): call_user_func_array('twitter_user_se...', Array) #10 /membri/iartist/portale/index.php(21): menu_execute_active_handler() #11 {main}

CommentFileSizeAuthor
#14 twitter.png50.64 KBnpralhad
#13 twitter.png50.64 KBnpralhad
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cruze72’s picture

Same here ...

saru1683’s picture

I have installed Drupal 7.14 with modules Twitter 7.x-4.1+5-dev and Oauth 7.x-3.0+18-dev.

during add account I got error message like
"Could not obtain a valid token from the Twitter API. Please review the configuration".

I got same error log.

juampynr’s picture

Did you configured your OAuth keys at the Twitter settings? Please have a look at the Twitter installation page, specially the parts that mention OAuth http://drupal.org/node/1346824.

deimos83’s picture

I followed everything, but nope..
In addition I have to report that when I click "Add account" there is no field for the account name to add, instead if I take an older version of this module( eg. 7.x-3.x) I am able to add an account when Oauth is not installed but then nothing too..

somms’s picture

I've had the same problem, but I've solved it.
The problem was that I didn't filled the "Callback URL" parameter in the Twitter application settings (in dev.twitter.com)

deimos83’s picture

I checked and double checked it but my callback url on twitter is the same of that in the twitter module...

timoa’s picture

After many tests, I just add the callback URL found in settings of Twitter Drupal module to the Twitter App settings (tab "Settings", field "Callback URL" and it work :)

marko42’s picture

#7 worked for me. Thanks timoa!

ianmen’s picture

The fix for me was to add the security option to place posts on Twitter in the twitter app settings.

juampynr’s picture

Status: Active » Fixed

Please everybody else review that the permissions of your Twitter app at dev.twitter.com are Read and Write. Note that changing this from Read only to Read and Write means that you need to re-authenticate your twitter accounts so they gain the new privileges.

jebuske’s picture

I've put in my consumer key and consumer secret correctly and have put the permissions to read and write. No, how do I re-authenticate my twitter account? I'm still getting the "Could not obtain a valid token from the Twitter API. Please review the configuration". error when I want to add an account

Thank you!

sujith7c’s picture

Yes. This works for me

npralhad’s picture

FileSize
50.64 KB

Hi jebuske

I hope you have confirmed following

  1. In case you have changed the permissions access in twitter then REGENERATE THE KEYS
  2. Make sure OAUTH settings are matching with twitter

At last please have a look at the attached screen as you must have to authenticate your account.

These steps have helped me and hope will help you as well.

npralhad’s picture

FileSize
50.64 KB

Hi jebuske

I hope you have confirmed following

  1. In case you have changed the permissions access in twitter then REGENERATE THE KEYS
  2. Make sure OAUTH settings are matching with twitter

At last please have a look at the attached screen as you must have to authenticate your account.

These steps have helped me and hope will help you as well.

Let me know in case still you have the problems :)

kikoalonsob’s picture

I have the same problem.

If i click "Go to twitter to add an authenticated account" in admin/config/services/twitter everything seems ok, i return to my site and see my account details.

The problem is when I try to login with a twitter account, it says "Invalid Twitter OAuth request" and in dblog it says:

exception 'TwitterException' with message 'Unauthorized' in /var/www/dev.mysite.com/htdocs/sites/all/modules/twitter/twitter.lib.php:135 Stack trace: #0 /var/www/dev.mysite.com/htdocs/sites/all/modules/twitter/twitter.lib.php(98): Twitter->request('https://api.twi...') #1 /var/www/dev.mysite.com/htdocs/sites/all/modules/twitter/twitter.lib.php(79): Twitter->auth_request('https://api.twi...') #2 /var/www/dev.mysite.com/htdocs/sites/all/modules/twitter/twitter.pages.inc(421): Twitter->get_access_token() #3 /var/www/dev.mysite.com/htdocs/includes/form.inc(1464): twitter_oauth_callback_form_validate(Array, Array) #4 /var/www/dev.mysite.com/htdocs/includes/form.inc(1404): form_execute_handlers('validate', Array, Array) #5 /var/www/dev.mysite.com/htdocs/includes/form.inc(1134): _form_validate(Array, Array, 'twitter_oauth_c...') #6 /var/www/dev.mysite.com/htdocs/includes/form.inc(846): drupal_validate_form('twitter_oauth_c...', Array, Array) #7 /var/www/dev.mysite.com/htdocs/includes/form.inc(704): drupal_process_form('twitter_oauth_c...', Array, Array) #8 /var/www/dev.mysite.com/htdocs/sites/all/modules/twitter/twitter.pages.inc(372): drupal_form_submit('twitter_oauth_c...', Array) #9 [internal function]: twitter_oauth_callback(Array, Array) #10 /var/www/dev.mysite.com/htdocs/includes/form.inc(798): call_user_func_array('twitter_oauth_c...', Array) #11 /var/www/dev.mysite.com/htdocs/includes/form.inc(339): drupal_retrieve_form('twitter_oauth_c...', Array) #12 /var/www/dev.mysite.com/htdocs/includes/form.inc(131): drupal_build_form('twitter_oauth_c...', Array) #13 [internal function]: drupal_get_form('twitter_oauth_c...') #14 /var/www/dev.mysite.com/htdocs/includes/menu.inc(517): call_user_func_array('drupal_get_form', Array) #15 /var/www/dev.mysite.com/htdocs/index.php(21): menu_execute_active_handler() #16 {main}

npralhad’s picture

Its a problem with your TWITTER secret key.

  • In case you have changed the permissions access in twitter then REGENERATE THE KEYS
  • Make sure OAUTH settings are matching with twitter

At last please have a look at the attached screen as you must have to authenticate your account.

These steps have helped me and hope will help you as well.

gantenx’s picture

Version: 7.x-4.1 » 7.x-5.4

I experienced this issue too. Consumer key and consumer secret has been set up correctly, but still no luck. I found this article: https://dev.twitter.com/discussions/1043. This issue probably comes from invalid timestamp.

Status: Fixed » Closed (fixed)

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

csedax90’s picture

same problem... i've tried with the latest solution of this post(https://dev.twitter.com/discussions/1043) but nothing appens... some ideas?

gantenx’s picture

I don't know if this work on yours, but try to synchronize your server time with NTP server. My issue solved after synchronizing server time. The issue seemed come from invalid timestamp.

phanophite’s picture

This worked for me as well even though my site is a Drupal 6 site.

OMD’s picture

experiencing the same issue with the same error log message

deardagny’s picture

Just clicking the "Go to Twitter to add an Authenticated Account" button after updating the access permissions on my Twitter application solved this issue for me.

truyenle’s picture

same issue none of the above work for me.

glass.dimly’s picture

I was getting this error about June of 2013 on my blog, possibly timed to a Twitter API change. I haven't really had time to work on it until now because I had forked the Twitter module and figured it was my fault. Still might be. But now I'm running on the latest stable.

I had two accounts activated. One used to be my "sitewide" twitter account, but this is a setting I can no longer find on the twitter account settings: /admin/settings/twitter

I re-authenticated my new twitter account, the account on which the app is hosted, but the one which was not previously my "sitewide" twitter account.

I was only able to resolve this issue when I re-authenticated the account that was previously the "sitewide" twitter account. Or perhaps all the accounts need to be authenticated?

After that I ran cron and started getting my tweets for my new, not-sitewide twitter account.

Suggested work-around: authenticate all Twitter accounts and remove non-authenticated ones.

Suggested fix: allow users to specify which Twitter account is being used to access the Twitter API.

I realize this is a 7x bug, but I'm running the latest stable 6x version: 6.x-5.1 with oauth 6.x-3.0-beta5. I think this information may be useful to subscribers on this thread.

cthshabel’s picture

I am receiving this error when using Rules to post to Twitter. Since each individual user needs to post to their own account, we use rules to post, instead of the post to twitter via the content type configuration.

Everything works fine when the [node-title] [node-url] is under the 140 character limit; however, it seems Twitter doesn't shorten this correctly when over the 140 limit. The title should be shortened to fix this, keeping the url. This is similar to this issue: https://www.drupal.org/node/797592 ... This patch is deprecated for newer versions, and custom tokens can be used easily to shorten the title.

The Post to Twitter submodule did propose a fix for this here: https://www.drupal.org/node/369224 but it doesn't get triggered when using the Rules (Twitter Actions) sub module. But the concept is the same. Check the title length and shorten if necessary.

Figured I would leave the notes here since I did receive this same error, and it was unrelated to apps.twitter.com permissions (Read & Write) and OAuth permissions on both sides. I imagine those items will typically be the solution for this issue.

rclemings’s picture

One more thing to check ...

I got this error when fetching tweets from non-authenticated users:

exception 'TwitterException' with message 'Authorization Required Not authorized.' in /path/to/sites/all/modules/contrib/twitter/twitter.lib.php:156 

(from /admin/reports/dblog, type "twitter)

The problem, I eventually figured out, was that one or more of the users had their tweets set to private. Unchecking their "tweets" box at /admin/config/services/twitter was the fix.

KhaledBlah’s picture

I, too, had this issue but instead my error message was 'Authorization Required' (see below) and once I filled the callback URL on the Twitter app settings page it worked. The callback URL is optional on twitter so maybe a warning message that it is required for this module to work would be a good idea.

exception 'TwitterException' with message 'Authorization Required' in <root>/sites/all/modules/twitter/twitter.lib.php:175 Stack trace: #0 <root>/sites/all/modules/twitter/twitter.lib.php(123): Twitter->request('https://api.twi...') #1 <root>/sites/all/modules/twitter/twitter.lib.php(55): Twitter->auth_request('https://api.twi...', Array) #2 <root>/sites/all/modules/twitter/twitter.pages.inc(405): Twitter->get_request_token(Array) #3 <root>/includes/form.inc(1519): twitter_auth_account_form_submit(Array, Array) #4 <root>/includes/form.inc(903): form_execute_handlers('submit', Array, Array) #5 <root>/includes/form.inc(385): drupal_process_form('twitter_auth_ac...', Array, Array) #6 <root>/includes/form.inc(130): drupal_build_form('twitter_auth_ac...', Array) #7 <root>/sites/all/modules/twitter/twitter.pages.inc(176): drupal_get_form('twitter_auth_ac...') #8 [internal function]: twitter_user_settings() #9 <root>/includes/menu.inc(527): call_user_func_array('twitter_user_se...', Array) #10 <root>/index.php(21): menu_execute_active_handler() #11 {main}

KhaledBlah’s picture

Never mind my last comment. Just saw that I should have been more attentative with the installation instructions ;-)