Twitter PHP REST API giving {"errors":[{"code":32,"message":"Could not authenticate you."}]}



I’m have Integrated Twitter Standard search API with in the application.

For some keywords, Initially Search API returned results normally for some days and then throwing following error.

{“errors”:[{“code”:32,“message”:“Could not authenticate you.”}]}

I have checked if the token has expired, but its not. I could do other activity with the same token.

Having issue sometimes is quite confusing.

Can anyone please help me out?

Thanks in advance


It sounds like something might be changing in your request authorization, how are you generating the Oauth details?



Thanks for the reply.

We are using Zend_Service_Twitter library for the version Zend 1.12

I have used following code for the reference.

            $twitter_accessToken  // We will fetch from the Twitter after User authentication using OAuth
            $token = unserialize($twitter_accessToken);

            $twitter = Api_Twitter::createTwitterObject($token);
            $searchText = $keyword;
	    $searchText = $searchText.' -'.$exclude;  // content to Exclude
	    $searchText = $searchText.'  filter:Images'; // To filter	 images/videos etc

            $options['count'] = '100';
            $options['tweet_mode'] = 'extended';
            if($language != 'any') {
                $options['lang'] = $language;

            $resultData = $twitter->searchTweets($searchText, $options);
            $decodedData = json_decode($resultData->getRawResponse(), true);

For end users, we provide option to add multiple Twitter networks with in our application.

So while adding the column to search, along with filters, we provide an option to choose from which Twitter Network the search to be executed.

The same code working for other Twitter Tokens (for other columns). But for some specific tokens, that too after some iterations, this error message coming. Then after, its stops pulling the data from API, for that Twitter Token.

Couldn’t get the exact scenario why this is happening.


I didn’t hear any solution on this in mean time.
Did anyone faced similar issue or any solution for the same?
Thanks in advance.



It looks like you’re not authenticating with Zend_Oauth as described in

What does $acc = new Zend_Oauth_Token_Access(); do?

I’m not a PHP Developer so maybe I’m missing something here, but the 32 error is thrown when badly authenticating to Oauth.



Thank you for the reply.

I have followed the OAuth pattern as mentioned in Twitter library for Zend in GitHub in Following link.

The same pattern worked for fetching results, when searched for a keyword in the first iteration.

On pulling data using next cursors, after some iterations, that too at some times this error is being thrown.


I’m at work right now and I don’t have access to Github :sweat_smile: … I’ll check on your code later today and hopefully I’ll have something to reply.


Hi Guys,
I thought, there could be some issue with my coding or issue in requesting format, so debugged the flow but couldn’t find any. That too same code is working fine for few days.

Then I planned Switching library could fix this.

From following Twitter mentioned Libraries link.

I have chosen below mentioned PHP library and integrated it with in the application.

For most of the Twitter access tokens it is working fine (Still working with no errors) similar to the previous library.

But, only for some user tokens (That are not expired, we could fetch timeline data with it), that too after pulling data for 2 to 3 days successfully, it is throwing Could not authenticate you error.

[errors] => Array
            [0] => Array
                    [code] => 32
                    [message] => Could not authenticate you.


This could be a rare scenario. Does anyone faced similar kind of issue?

Thanks in advance.


Is the failing search request always failing for the specific users? If you perform that exact same search with different users does it succeed?


Hi abraham,

Thank you for replying,

No, It is happening randomly for random access tokens.

I tried the same keyword with other access token by applying same filters, It worked and is still pulling data with no errors.

For the same access token also, initially for some days it pulled data successfully, Later stopped by throwing error for that search keyword…

I also checked If the same access token (With out refreshing the token) used for searching different keyword results after stopped fetching, in this scenario also it worked successfully with no errors.



Anyone found solution to this kind of rare scenario issue?

Happy to hear form you.

Thanks in advance.


Are the keys and tokens being sent as an array or as query style key/value pairs (key1=val1&key2=val2)? If the content-type is sometimes being set to multipart/form, then you might be getting rejected on that first “incomplete” request.