Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

401 - "Could not authenticate you (header rejected by twitter)." when trying to upload a picture with PHP to TwitPic

I'm using meltingice's API for TwitPic and when I try to upload a picture I get a 401 error with the message "Could not authenticate you (header rejected by twitter)".

My headers (retrieved from the HTTP Request2 object) are:

Array
(
    [user-agent] => HTTP_Request2/2.0.0 (http://pear.php.net/package/http_request2) PHP/5.2.17
    [x-verify-credentials-authorization] => OAuth realm="http://api.twitter.com/", oauth_consumer_key="****************", oauth_signature_method="HMAC-SHA1", oauth_token="#########-******************", oauth_timestamp="1325192643", oauth_nonce="***********", oauth_version="1.0", oauth_signature="****************%3D"
    [x-auth-service-provider] => https://api.twitter.com/1/account/verify_credentials.json
    [content-type] => multipart/form-data
)

I made sure that the verify_credentials signature is using GET, and I can't see any other issues.

What am I doing wrong?

Thanks :)

EDIT: Here's my source code.

$venue = $this->Venue->findById($venueId);
$twitterData = json_decode($venue['Venue']['twitter_data']);
$token = $twitterData->token;
$secret = $twitterData->secret;
$this->Twitter->loginTwitterUser($token, $secret);
require_once(WWW_ROOT.'twitpic/TwitPic.php');

$twitpic = new TwitPic('**********', '*******', '*********', $token, $secret);


$result['result'] = $twitpic->upload(array('media'=> '/home/todays/public_html/tsm/app/webroot/files/uploads/LOGOA7V1_10.png', 'message'=> 'test'));

And I'm sure that the token, secret, and app credentials are correct as they work in my Twitter API without any problems. I've also double checked the Twitpic API key.

like image 563
Nick Badal Avatar asked Dec 29 '11 21:12

Nick Badal


1 Answers

After checking the TwitPic documentation I noticed that the 401 error was explained: This method will return a 401 Unauthorized if the OAuth header was not present or could not be verified with Twitter.

You're saying you made sure that the verify_credentials signature is using GET while the API only accepts POST. Maybe that's your problem?

Here's the example code related to the API you're using:

  • https://github.com/meltingice/php-twitpic/blob/master/EXAMPLE.php
like image 90
Runar Jørgensen Avatar answered Sep 24 '22 23:09

Runar Jørgensen