Retweeting issue in PHP


#1

Hey there !
I’m trying to retweet something with my php app. Seems that the oAuth signature is missing for retweeting something, but i can’t find how to do it. Here is my code :

$id = ‘241259202004267009’; // tweet’s id
$retweet = new TwitterOAuth($myConsumerKey, $myConsumerSecret ,$oauthToken, $oauthTokenSecret);
$retweet->host = “https://api.twitter.com/1.1/”;
$retweet->ssl_verifypeer = TRUE;
$retweet->post(‘statuses/retweet/’.$id);

Unfortunately, i always get the “Bad Authentication Data” twitter error… The problem is that i can generate oAuth signature from the oAuth Tool here (https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/%3Aid) but i would like it to be done automatically in my code. Any ideas ? Thanks


#2

It sounds like something is off with how the library is encoding this request, perhaps in how it’s presenting the Authorization HTTP header or similar. Do you know what the request looks like when it leaves your serve?


#3

Thanks for your answer.
Don’t really know. I tried to print the http_info request ( var_export($retweet->http_info); ) and i got this :

array ( ‘url’ => ‘https://api.twitter.com/1.1/statuses/retweet/402594649015353340.json’, ‘content_type’ => ‘application/json; charset=utf-8’, ‘http_code’ => 404, ‘header_size’ => 653, ‘request_size’ => 484, ‘filetime’ => -1, ‘ssl_verify_result’ => 0, ‘redirect_count’ => 0, ‘total_time’ => 0.594081, ‘namelookup_time’ => 2.2E-5, ‘connect_time’ => 0.136142, ‘pretransfer_time’ => 0.434378, ‘size_upload’ => 276, ‘size_download’ => 68, ‘speed_download’ => 114, ‘speed_upload’ => 464, ‘download_content_length’ => 68, ‘upload_content_length’ => 276, ‘starttransfer_time’ => 0.594076, ‘redirect_time’ => 0, ‘redirect_url’ => ‘’, ‘primary_ip’ => ‘199.16.156.40’, ‘certinfo’ => array ( ), ‘primary_port’ => 443, ‘local_ip’ => ‘192.168.1.10’, ‘local_port’ => 51287, )

And if i load the url in my browser window i get the usual “Bad Authentication data” error.


#4

Hmm… that debug seems to suggest that the response you’re getting back from the API is actually a HTTP 404 (not that your auth wasn’t considered valid).

That means the ID of the tweet you’re trying to retweet isn’t correct – I see that it ends with zero – which happens when a language that can’t process 64 bit integers correctly tries to consume one of our Tweet (or user) IDs… are you fetching that ID from another API response? If so, fetch it from a “id_str” field instead of an “id” – your programming language seems to be silently munging the integer.


#5

i got the same issue .Please help in resolving it.
I am using fabric in android to re-tweet the tweet but getting the “403 Forbidden” error in my log