Could not authenticate with OAuth.

@Darkwater124 Darkwater


I'm using the tmhOAuth library for my website to link accounts, update statusses, etc. Linking accounts works fine, no errors. But when I'm trying to post a status update, I'm getting this error:

{"error":"Could not authenticate with OAuth.","request":"\/1\/account\/verify_credentials.json"}

Using the following code:

  1. <?php
  3. /**
  4.  * Verify the user token and secret works. If successful we will be given the
  5.  * details of the user. If not an error explaining why will be returned.
  6.  *
  7.  * Although this example uses your user token/secret, you can use
  8.  * the user token/secret of any user who has authorised your application.
  9.  *
  10.  * This example differs from others in that it will reattempt a request if
  11.  * the timestamp is detected to be off from the Twitter servers.
  12.  *
  13.  * Instructions:
  14.  * 1) If you don't have one already, create a Twitter application on
  15.  *
  16.  * 2) From the application details page copy the consumer key and consumer
  17.  *      secret into the place in this code marked with (YOUR_CONSUMER_KEY
  18.  *      and YOUR_CONSUMER_SECRET)
  19.  * 4) Visit the 'My Access Token' screen linked to from your application
  20.  *      details page
  21.  * 5) Copy the user token and user secret into the place in this code marked
  22.  *      with (A_USER_TOKEN and A_USER_SECRET)
  23.  * 6) Visit this page using your web browser.
  24.  *
  25.  * @author themattharris
  26.  */
  28. require '../tmhOAuth.php';
  29. require '../tmhUtilities.php';
  30. $tmhOAuth = new tmhOAuth(array(
  31.   'consumer_key'    => '###########',     // Got this from Consumer key
  32.   'consumer_secret' => '##################',     // Got this from Consumer secret
  33.   'user_token'      => '###-############',     // Got this from Access token
  34.   'user_secret'     => '#################',     // Got this from Access token secret
  35. ));
  37. // for the demo set the timestamp to yesterday
  38. $tmhOAuth->config['force_timestamp'] = true;
  39. $tmhOAuth->config['timestamp'] = strtotime('yesterday');
  41. $code = tmhUtilities::auto_fix_time_request($tmhOAuth, 'GET', $tmhOAuth->url('1/account/verify_credentials'));
  43. if ($code == 200) {
  44.   if ($tmhOAuth->auto_fixed_time)
  45.     echo 'Had to auto adjust the time. Please check the date and time is correct on your device/server';
  47.   tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
  48. } else {
  49.   tmhUtilities::pr(htmlentities($tmhOAuth->response['response']));
  50. }
  52. ?>

Access level: R&W+DM

I think there is a problem with the user_token and the user_secret. I already searched the interwebs for solutions, I also found this exact problem, but none of the solutions work.

Please help me.


PS. I also saw some threads with formatted code. How do I do that?

2 years 39 weeks ago


@strategic_opt Strategic Options

I am having the similar problem. Using tmhOAuth library and I receiving the same error. Have not found a solution on the interwebs either...


2 years 39 weeks ago
@suhel_khan Suhel Khan

I am having issues while trying to post a tweet using an App from Nokia S60 device. Following is the issue:-
1) I want to login into Twitter from Nokia Web browser on N8. Previously it is working fine but form last 4 days, I am getting problem on login screen. I am unable to click signin because of Javascript/jquery thing.
2) On computer browser if i click on user_email_id then on "blur" and on "keypress" event is fired but if i do the same on mobile browser there is no action performed there.
3) I think twitter have issue with "Onblur" and "OnKeypress" event of javascript/jquery on mobile web browser.
4) I tried to login from default browser on Nokia device, effect is browser crashes because of issue with javascript.

This is urgent please help.

2 years 39 weeks ago
@marquito marquito

anyone solved this? I'm having this issue 13 weeks later.

2 years 25 weeks ago
@Darkwater124 Darkwater

Im using another library now. @abraham his lib. Contact him or me if you want details or a how-to or whatever

2 years 25 weeks ago
@devsri88 Devesh Srivastava

I am also getting the same issue but I am using EpiOAuth Lib............Can anyone please help me out

Thanks in Advance

2 years 24 weeks ago
@diet_nutrition nutrition and diet

Today I wanted to connect my Word Press blog site with my twitter account but have no idea where to find the twitter consume key or consumer secret .

Everywhere I look becomes more complex. I am not computer literate and this makes it more frustrating.
Now when I go to my wordpress site it is asking for the above, yet on Twitter it says it is okay

Can someone help please. Don't send links just show me where these keys are found.
Please email using the address on my account.

Thank you

2 years 24 weeks ago
@sravanthi97 sravanthi

go to twitter developers site there is a link called create ur application .
enter the details and accept terms and conditions and set create access token it displays key and secret

2 years 24 weeks ago
@TweetSnapz Fiona Mangru

I am having the same problem but I am using @abraham library. Below is my code. I just want to verify my user and be able to see home_timeline. I am able to pull information from public_timeline.

  1. <?php
  2. session_start();
  3. require_once('lib/twitteroauth/twitteroauth.php');
  4. require_once('lib/config.php');
  6. function getSessionToken(){
  7.     /* Build TwitterOAuth object with client credentials. /
  8.    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
  10.   / Get temporary credentials. /
  11.    $request_token = $connection->getRequestToken(OAUTH_CALLBACK);
  12.   / Save temporary credentials to session. /
  13.    $_SESSION['oauth_access_token'] = $token = $request_token['oauth_token'];
  14.   $_SESSION['oauth_access_token_secret'] = $request_token['oauth_token_secret'];
  16.   / If last connection failed don't display authorization link. /
  17.  switch ($connection->http_code) {
  18.      case 200:
  19.         / Build authorize URL and redirect user to Twitter. /
  20.         $url = $connection->getAuthorizeURL($token);
  21.         header('Location: ' . $url); 
  22.         break;
  23.    default:
  24.      / Show notification if something went wrong. /
  25.        echo 'Could not connect to Twitter. Refresh the page or try again later.';
  26.    }
  27. }
  29. / If access tokens are not available redirect to connect page. /
  30. if ((!isset($_SESSION['oauth_access_token'])) || ($_SESSION['oauth_access_token'])=='') 
  31. {
  32.    getSessionToken();
  33. }
  34. / Get user access tokens out of the session. /
  35. $access_token = $_SESSION['oauth_access_token'];
  37. $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret']);
  39. / If method is set change API call made. Test is called by default. /
  40. $content = $connection->get('account/rate_limit_status');
  41. echo "Current API hits remaining: {$content->remaining_hits}.<br>";
  43. / Get logged in user to help with tests. */
  44. $user = $connection->get('account/verify_credentials');
  45. print_r($user);
  47. session_destroy();
  48. ?>
2 years 24 weeks ago
@kurrik Arne Roomann-Kurrik

I'd say that one of the biggest problems with this code is that every line that does anything related to authorization is commented out. Have you tried configuring the library according to the documentation?

2 years 23 weeks ago
@kirtipatel4 Kirti Patel

Hi guys,

I'm facing the same issue. I am using @abraham library, which is giving me the following error:

There is no request token for this page. That's the special key we need from applications asking to use your Twitter account. Please go back to the site or application that sent you here and try again; it was probably just a mistake.

Any idea as to what maybe going wrong?

2 years 6 weeks ago
@therealhoffer Andrew Hoff

@abraham's library isn't giving you that error, twitter is. Your problem is that you are not passing in an oauth token to the authorize url ( The correct URL would be something like I'm using tmhOAuth library. This oauth token is obtained from extract_params on the response from

1 year 38 weeks ago