401 - "Failed to authenticate you (header rejected by twitter)." when trying to upload an image from PHP to TwitPic

I use the casting API for TwitPic , and when I try to upload the image, I get a 401 error with the message "You could not authenticate (header rejected by twitter)."

My headers (extracted from the HTTP Request2 object):

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 the verify_credentials signature uses GET and I see no other problems.

What am I doing wrong?

Thanks:)

EDIT : Here is 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 credentials of the token, secrets and applications are correct, as they work in my Twitter API without any problems. I also double checked the Twitpic API key.

+6
source share
1 answer

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

You say make sure the verify_credentials signature uses GET when the API accepts only POST. Maybe your problem?

Here is an example of the code associated with the API used:

+2
source

Source: https://habr.com/ru/post/904703/


All Articles