Hello,

I am trying to get the recent mentions with the twitter api but it
returns the error "Incorrect signature".

Here's my PHP code:

<?php
$time = time() + 10800;

$target = urlencode("http://api.twitter.com/1/statuses/mentions.xml?
count=20");
$oauth_consumer_key = urlencode("****");
$oauth_nonce = urlencode(sha1($time));
$oauth_signature_method = urlencode("HMAC-SHA1");
$oauth_token = urlencode("****");
$oauth_time = $time;
$oauth_version = urlencode("1.0");

$result = "GET&$target&oauth_consumer_key%3D$oauth_consumer_key
%26oauth_nonce%3D$oauth_nonce%26oauth_signature_method%3D
$oauth_signature_method%26oauth_timestamp%3D$oauth_time%26oauth_token
%3D$oauth_token%26oauth_version%3D$oauth_version";

$consumer_token_secret = urlencode("****");
$oauth_token_secret = urlencode("****");
$combine = "$consumer_token_secret&$oauth_token_secret";

$signature = urlencode(base64_encode(hash_hmac("sha1", $result,
$combine, true)));

$auth = "OAuth oauth_nonce=\"$oauth_nonce\", oauth_signature_method=
\"$oauth_signature_method\", oauth_timestamp=\"$oauth_time\",
oauth_consumer_key=\"$oauth_consumer_key\", oauth_token=\"$oauth_token
\", oauth_signature=\"$signature\", oauth_version=\"$oauth_version\"";

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://api.twitter.com/1/statuses/
mentions.xml?count=20");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: $auth"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $signature);

$result = curl_exec($curl);
echo $result;
?>

Am I not generating the signature correctly?

-- 
Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: 
http://groups.google.com/group/twitter-development-talk

Reply via email to