Hello all,
I am using Perl’s Net::OAuth module. Here is the part of my code that is failing. Please assume that $message, $consumer_key, $consumer_secret, $url, $token and $token_secret are defined correctly, because I’ve checked them a million times. Also, my clock is set correctly.
my $ua = LWP::UserAgent->new;
my $request = Net::OAuth->request("protected resource")->new(
consumer_key => $consumer_key,
consumer_secret => $consumer_secret,
request_url => $url,
request_method => 'POST',
signature_method => 'HMAC-SHA1',
timestamp => time,
nonce => int(rand(2 ** 32)),
token => $token,
token_secret => $token_secret,
extra_params => {status => $message},
)
$request->sign;
my $response = $ua->post($request->to_url);
Pretty simple, yes? But every time, I get “401 Unauthorised - Could not authenticate with OAuth”. Here is what the POST request looks like:
/1/statuses/update.json?oauth_consumer_key=P5xo2gguKuZPlgFKJIwDWg&oauth_nonce=3058633389&oauth_signature=V3y%2F0xWFoXhWVxdQo44TJ%2Bg4k1A%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1328448285&oauth_token=15043295-NnGYKkq7fGxdEAraIba2zL6kPunXecwei47MYuY8&oauth_version=1.0&status=foo
I don’t think it’s an encoding issue because, really, how many ways are there to encode “foo”?
FWIW, this problem is not unique to Twitter. I get the same error posting to StatusNet (using its Twitter-compatible API), except with a slightly more useful error message “Invalid signature”. I was able to get around it by disabling the signature verification on my locally-installed StatusNet, but obviously I can’t do that with Twitter!
I’ve spent a couple of days bashing my head against the wall. Does anyone have any brilliant ideas, other than not using Net::OAuth (since this is a very widely-used module, and ought to be able to work)?
Thanks!