简体   繁体   English

如何使用Perl和仅LWP :: UserAgent更新我的Twitter状态?

[英]How can I update my Twitter status with Perl and only LWP::UserAgent?

I'm trying to update my status through the Twitter API and OAuth. 我正在尝试通过Twitter API和OAuth更新我的状态。

I get stuck on the last step, the status update. 我被困在最后一步,状态更新。 Here's my code. 这是我的代码。

The header: 标题:

$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");

The post to http://api.twitter.com/1/statuses/update.json made with lwp useragent: 使用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", 

and what i get: 我得到了什么:

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."}

Does anyone has an idea? 有没有人有想法? i'm stuck there, and it's really frustrating. 我被困在那里,这真的令人沮丧。

Well, if you don't want to use Net::Twitter or Net::Twitter::Lite , you should probably at least have a look at the code and see what they are doing. 好吧,如果你不想使用Net :: TwitterNet :: Twitter :: Lite ,你应该至少看看代码并看看他们在做什么。

Based on the error you're getting, it looks like you aren't doing the OAuth handshake properly. 根据您获得的错误,您似乎没有正确进行OAuth握手。 Maybe it's as simple as a missing field, but I suspect there is something more missing from your simple approach (I don't know anything about OAuth specifics - sorry). 也许它就像一个缺失的领域一样简单,但我怀疑你的简单方法还有一些缺失(我对OAuth细节一无所知 - 抱歉)。 You could also go directly to the OAuth module that Twitter::Lite is using Net::OAuth::Simple to see how they handle it. 您也可以直接进入OA :: Lite使用Net :: OAuth :: Simple来查看它们如何处理它的OAuth模块。

Don't use OAuth, simply do it the old way and tag ?source=twitterandroid onto the end, like so: 不要使用OAuth,只需按照旧方式执行并标记?source = twitterandroid到最后,如下所示:

http://api.twitter.com/1/account/rate_limit_status.json?source=twitterandroid http://api.twitter.com/1/account/rate_limit_status.json?source=twitterandroid

I tested that a couple of weeks ago and confirmed the method still works. 几个星期前我测试过,并确认该方法仍然有效。 Please don't consider this a workaround, it is simply legacy functionality that will quickly disappear but might enable you to do something for now. 请不要认为这是一种解决方法,它只是遗留的功能,很快就会消失,但可能会让你现在做点什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM