开发者

Rails app using Oauth to post to Twitter, getting "not authorized" when running in production server. OK in localhost

I'm trying to use Twitter's Oauth Single Token for posting from a rails app to my twitter feed (single user use-case is perfect for my app). This Is what I'm talking about.

Here's the relevant part of my code:

twitter_consumer_key = 'AAAAAA...'
twitter_consumer_secret = 'BBBBBB///'
oauth_token = 'CCCCC....'
oauth_token_secret = 'DDD.....'

consumer = OAuth::Consumer.new(twitter_consumer_key, twitter_consumer_secret, :site => "http://api.twitter.com", :scheme => :header)
access_token = OAuth::AccessToken.from_hash(consumer, :oauth_token => oauth_token, :oauth_token_secret => oauth_token_secret)
response = access_token.post("http://api.twitter.com/1/statuses/update.json",开发者_开发百科 {:status => "Coffee's ready at 191 Peachtree!! "+Time.now.to_i.to_s})
logger.info response.inspect

When I run this in my local machine, everything goes well and the post is created on my feed. When I run it on my production server (centos5.5, Apache 2, Passenger, Rails 3.0.4) I get "HTTPUnauthorized".

Any ideas on how to troubleshoot this?

Thanks in advance.


Try with filling Callback URL in settings of your application on dev.twitter.com. Should be something like that:

Callback URL http://yousite.com/auth/twitter/callback


Per abraham's comment, I'm adding the solution as an answer instead of a comment:

My server's timezone was incorrectly set so I was getting the following error in the response body:

{"request":"\/1\/statuses\/update.json","error":"Timestamp out of bounds"} 

I set the time and timezone correctly and now it's working fine.

:)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜