我正在尝试通过Twitter API和OAuth更新我的状态。

我陷入了最后一步,状态更新。这是我的代码。

标头:

$ua->default_header('Content-Type' => "application/x-www-form-urlencoded");
$ua->default_header('oauth_signature' => "$signature");
$ua->default_header('Authorization' => '"OAuth realm="Twitter API"');
$ua->default_header('oauth_consumer_key' => "blablabla");
$ua->default_header('oauth_nonce' => "$nonce");
$ua->default_header('oauth_signature_method' => "HMAC-SHA1");
$ua->default_header('oauth_timestamp' => "$epoch");
$ua->default_header('oauth_token' => "$token_final");
$ua->default_header('oauth_version' => "1.0");


由lwp useragent发表到http://api.twitter.com/1/statuses/update.json的帖子:

'oauth_signature'=>"$signature",
'status'=>'Bientot',
'oauth_consumer_key'=>'blabla',
'oauth_signature_method'=>'HMAC-SHA1',
'oauth_nonce'=>"$nonce",
'oauth_timestamp'=>"$epoch",
'oauth_token'=>"$token_final",
'oauth_version'=>"1.0",


而我得到的是:

HTTP/1.1 401 Unauthorized
Cache-Control: no-cache, max-age=300
Connection: close
Date: Wed, 29 Sep 2010 14:36:48 GMT
Server: hi
Vary: Accept-Encoding
WWW-Authenticate: Basic realm="Twitter API"
Content-Length: 75
Content-Type: application/json; charset=utf-8
Expires: Wed, 29 Sep 2010 14:41:48 GMT
Client-Date: Wed, 29 Sep 2010 14:36:49 GMT
Client-Peer: 128.242.240.29:80
Client-Response-Num: 1
Set-Cookie: _twitter_sess=BAh7DjoTc2hvd19oZWxwX2xpbmswOg5yZXR1cm5fdG8iYWh0dHA6Ly9hcGku%250AdHdpdHRlci5jb20vb2F1dGgvYXV0aG9yaXplP29hdXRoX3Rva2VuPXpMc2d2%250AV2U5aHBvSWNOSW5rOFFkYUNrN1NQSlozZW1VcUNpckNxWkZvOhVpbl9uZXdf%250AdXNlcl9mbG93MDoTcGFzc3dvcmRfdG9rZW4iLWZiNzEyNTAzMGNiYTk1NTU1%250ANDE0OGExM2UxN2U2Yzc1ZmY2YjUzMDE6CXVzZXJpBLWRPgYiCmZsYXNoSUM6%250AJ0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2Vk%250AewA6B2lkIiU0MGUyNmQzNjRmYmI4YThlODgwN2MwZWYzYzNlOGJiYjoMY3Ny%250AZl9pZCIlZTUzZjY0OGIxMWZiOTA0OWQzM2FlOGI4NjYzZDA5NTI6D2NyZWF0%250AZWRfYXRsKwhe%252FkpTKwE%253D--3b624de9adb8de40ff8a3f0a5780f2b18b6abd44; domain=.twitter.com; path=/
Status: 401 Unauthorized
X-Runtime: 0.00264

{"request":"/1/statuses/update.json","error":"Could not authenticate you."}


有人有主意吗?我被困在那里,真令人沮丧。

最佳答案

好吧,如果您不想使用Net::TwitterNet::Twitter::Lite,则可能至少应该看看代码,看看它们在做什么。

根据收到的错误,您似乎没有正确执行OAuth握手。也许就像缺少字段一样简单,但是我怀疑您的简单方法还缺少一些东西(我对OAuth的具体情况一无所知。)您也可以直接转到Twitter :: Lite使用Net::OAuth::Simple的OAuth模块,以了解他们如何处理它。

关于perl - 如何使用Perl和仅LWP::UserAgent更新Twitter状态?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3823563/

10-15 19:05