Need help in Twitter api (Abraham's TwitterOAuth: Could Not Authenticate You Problem)



I am using Abraham’s TwitterOauth library to build an application that will collect oauth token and oauth token secret for each user and save it to database. So that later I can tweet on behalf of them.

I am doing it correctly. When user clicks on Allow this Application my app is getting authorized and user is redirected to the callback. I am also getting the Oauth token and Oauth token secret. But it’s not working when it comes to update status or read timeline or do anything else with user’s account.

I have read and write access in settings. My consumer keys and secret are correct.

It says Could Not Authenticate You… What might be the problem? Please see my code below-

Here is the code for index.php (URL for the application):

require_once 'twitteroauth.php';
require_once 'OAuth.php';
define("CONSUMER_KEY", "My key here");
define("CONSUMER_SECRET", "my secret here");
$tok = $to->getRequestToken($_REQUEST['oauth_verifier']);
$request_link = $to->getAuthorizeURL($tok);
$_SESSION['oauth_access_token']= $tok['oauth_token'];
$_SESSION['oauth_access_token_secret'] = $tok['oauth_token_secret'];
header("Location: $request_link");

Code For callback.php:

require_once 'twitteroauth.php';
require_once 'OAuth.php';
define("CONSUMER_KEY", "My Key");
define("CONSUMER_SECRET", "My Secret");
if ((!isset($_SESSION['oauth_access_token'])) || ($_SESSION['oauth_access_token'])=='') 
$to = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_request_token'], $_SESSION['oauth_request_token_secret']);
$token_credentials = $to->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['oauth_access_token'] =$token_credentials['oauth_token'];
$_SESSION['oauth_access_token_secret'] = $token_credentials['oauth_token_secret'];
$to=new TwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET,$_SESSION['oauth_access_token'],$_SESSION['oauth_access_token_secret']);
$content = $to->post('statuses/update', array('status' => 'Hello Twitter')); 

It gives the following Output:

object(stdClass)#5 (2) { [“error”]=> string(27) “Could not authenticate you.” [“request”]=> string(23) “/1/statuses/update.json” }

It says “Could Not Authenticate You”…

Any help will be highly appreciated…

Thanks A Lot!


I am also looking for a solution to this…


I got the solution, thanks to Abraham. In second file oauth_request_token should be changed to oauth_access_token.


I am also facing the same issue, and need to find a solution soon as im running on a deadline date.

Sandeep can i ask, when you say oauth_request_token should be changed to oauth_access_token, which exact line might you be referring to?




plz help because i am also facing the same problem


maybe he mistyped code in callback file line 9


Anyone found a solution for this?








maybe it’s because you are using the twitter API version 1 try to use version 1.1


I can’t access my android application to twitter.
If i access my phone to android twitter,they said that
you are wrong number.


Hi, im new in php. how to pass a oauth value. in my site invalid message will be displayed.