J7mbo / twitter-api-php

The simplest PHP Wrapper for Twitter API v1.1 calls
MIT License
1.82k stars 800 forks source link

POST gives me {"errors":[{"message":"Could not authenticate you","code":32}]} #64

Closed rvalsan closed 9 years ago

rvalsan commented 10 years ago

Hi,

My GET calls works perfect but I cant seem to post no matter what I tried. I tried single word statuses, urlencoding etc.

GET (Works)

/\ URL for REST request, see: https://dev.twitter.com/docs/api/1.1/ **/ $url = 'https://api.twitter.com/1.1/statuses/mentions_timeline.json'; $requestMethod = 'GET';

/\ GET fields required by the URL above. See relevant docs as above **/ $getfield = '?count=5';

/\ Perform a POST request and echo the response **/ $twitter = new TwitterAPIExchange($settings); $txtTwitter = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();

POST (Not working)

/\ URL for REST request, see: https://dev.twitter.com/docs/api/1.1/ **/ $url = 'https://api.twitter.com/1.1/statuses/update.json'; $requestMethod = 'POST';

/\ POST fields required by the URL above. See relevant docs as above **/ $postfields = array('status'=> 'test', 'in_reply_to_status_id' => 'rvalsan' );

/\ Perform a POST request and echo the response **/ $twitter = new TwitterAPIExchange($settings); echo $twitter->buildOauth($url, $requestMethod) ->setPostfields($postfields) ->performRequest();

Both use the same settings /\ Set access tokens here - see: https://dev.twitter.com/apps/ **/ $settings = array( 'oauth_access_token' => "token", 'oauth_access_token_secret' => "secret", 'consumer_key' => "key", 'consumer_secret' => "secret" );

J7mbo commented 10 years ago

Could you tell me what you get returned from your POST request?

rvalsan commented 10 years ago

This is the return JSON

{"errors":[{"message":"Could not authenticate you","code":32}]}

rvalsan commented 10 years ago

I've tried with both

/\ POST fields required by the URL above. See relevant docs as above **/ $postfields = array('status'=> 'test' );

and

/\ POST fields required by the URL above. See relevant docs as above **/ $postfields = array('status'=> '@rvalsan test', 'in_reply_to_status_id' => 'rvalsan' );

both give me the same error

AbiertaMente commented 10 years ago

bleh, this is exactly what i posted in my issue report (which has been closed without a patch) as I said, use POST if twitter api allows it is he best idea and it should at least work, the problem is he content-type

rvalsan commented 10 years ago

Sentencia, you're reply is not clear. The current method doesn't allow us to add content-type.

What's the work around?

J7mbo commented 10 years ago

It's to do with the type posted by the wrapper, I'll take a look and see what the best way of sorting this is.

rvalsan commented 10 years ago

Thanks :)

ndamnjanovic commented 10 years ago

Did you guys manage to solve this (some workaround)? I have the same issue, can't post tweet, and that's the 'only' thing that I need. Get requests work fine, but when trying to post tweet, getting 'Could not authenticate you, code 32'.

Here's the code:

$url = 'https://api.twitter.com/1.1/statuses/update.json';
$requestMethod = 'POST';
$postField = 'status=testing';

$settings = array(
'oauth_access_token' => '%token%',
'oauth_access_token_secret' => '%tokensecret%',
'consumer_key' => '%consumerkey%',
'consumer_secret' => '%consumersecret%');

 $twitter = new TwitterAPIExchange($settings);
 echo $twitter->setPostfields($postField)
              ->buildOauth($url, $requestMethod)                 
             ->performRequest();   

Thanks!

J7mbo commented 10 years ago

@ndamnjanovic setPostFields() requires an array of post field keys and values. You can see this here. If you have error reporting turned on, which you should have in the development environment, you'll see you're not passing the right parameter types to this method.

You need:

$postFields = array('status' => 'testing'); like the documentation shows on the front page.

Add ini_set('display_errors', true); at the top of your script to see errors.

ndamnjanovic commented 10 years ago

Thanks for incredibly fast response, and so sorry for wasting your time!

lakshmananvelusamy commented 9 years ago

@J7mbo Hi James, Thanks for the wonderful utility.

I am using your latest library. The get calls are going fine but the post calls are returning "{"errors":[{"code":32,"message":"Could not authenticate you."}]}". The tokens seem okay and the app has both read & write permissions. Could you please help?

J7mbo commented 9 years ago

Hi @lakshmananvelusamy, could you open your own new issue and also paste the code in that you are using.

lakshmananvelusamy commented 9 years ago

Hi James, Opened https://github.com/J7mbo/twitter-api-php/issues/145. Thanks!

mehulsbhandari commented 8 years ago

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

Please Help !!

J7mbo commented 8 years ago

Can you post your code? Cheers.

On 2 May 2016, at 13:04, mehulsbhandari notifications@github.com wrote:

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

Please Help !!

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

mehulsbhandari commented 8 years ago

Thanks for reply

require_once('TwitterAPIExchange.php');

$settings = array( 'oauth_access_token' => "XXXXXXXXXXXX", 'oauth_access_token_secret' => "YXXXXXXXXXXXXXXX", 'consumer_key' => "XXXXXXXXXXXXXX", 'consumer_secret' => "XXXXXXXXXXXXXXXX" );

$url = 'https://api.twitter.com/1.1/followers/list.json'; $getfield = '?username=mehulsbhandari&skip_status=1'; $requestMethod = 'GET'; $twitter = new TwitterAPIExchange($settings); $json = $twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest();
print_r(json_decode($json));

mehulsbhandari commented 8 years ago

I have also change ... TwitterAPIExchange.php

$options = array( CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $this->url, \ CURLOPT_SSL_VERIFYPEER => false,** CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, );

mehulsbhandari commented 8 years ago

@J7mbo Please Help

mehulsbhandari commented 8 years ago

Done .. Thanks ... Create New App Done.. :+1:

mynote commented 8 years ago

Most common problem is that there is an error in the consumer key or secret if you get the Could not authenticate you.

This usually happens if you copy/paste it from the twitter site. It has a whitespace at the beginning of the customer key which is not visible in all IDEs.

Please revalidate it using notepad or another editor and remove all whitespaces at the end and beginning of your data.

SunnyKart commented 7 years ago

Thanks man #mynote u just saved my day

Eng-Fouad commented 7 years ago

I was following the official documentation to construct the signature and I was adding include_entities for every request which is wrong. I removed it and then everything works fine.