Twitpic OAuth - I'm Stuck
Twitpic has implemented an OAuth API. No more having to hand out passwords to all and sundy. Only I'm too much of a dunderhead to get it working. Perhaps it's a combination of heatstroke or this rotten head-cold, but I just can't see what I'm doing wrong. Any help much appreciated.
The easy bit.
It's easy to post the data to Twitpic
$media_data = array( 'media' => '@'.$_FILES['media']['tmp_name'], 'message' => html_entity_decode($_POST['message']), 'key'=>'123465789132465' ); curl_setopt($ch,CURLOPT_POSTFIELDS,$media_data);
OAuth Credentials
Using Abrahams OAuth library for PHP, it's easy to get the required OAuth data.
require_once('OAuth.php'); // instantiating OAuth customer $consumer = new OAuthConsumer(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET); // instantiating signer $sha1_method = new OAuthSignatureMethod_HMAC_SHA1(); // user's token list($oauth_token, $oauth_token_secret) = explode('|', $GLOBALS['user']['password']); $token = new OAuthConsumer($oauth_token, $oauth_token_secret); // signing URL $fakeurl = 'https://twitter.com/account/verify_credentials.xml'; $request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $fakeurl, array()); $request->sign_request($sha1_method, $consumer, $token); $OAuthurl = $request->to_url();
The Tricky Bit
I'm following the header example in the API documentation. Passing these variable to Twitpic is where I seem to go wrong.
$header = array( 'X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.json', 'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/"' );
I then modify the second header so it reads
"X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/", oauth_consumer_key="aaaaaaa", oauth_nonce="bbbbbbbbbbb", oauth_signature="ccccccccccccc%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="123456798", oauth_token="15948715-dddddddddd", oauth_version="1.0""
The Error
401 "Could not authenticate you (header rejected by twitter)."
GAH!
$header = array('X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.json', 'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/"');
Now at least the error I get back is from Twitter!rik says:
toshi says:
toshi says: