Twitter 的 Ruby OAuth 出现 401 错误
x我已经花了好几天的时间来让 Twitter 使用 Ruby 进行身份验证,但我没有任何运气。
我的第一次尝试是这样的:
class TwitterController < ApplicationController
def index
@callback_url = "http://dev.twipler.com:3000/twitter/auth"
@auth= TwitterOAuth::Client.new( :consumer_key => "xxx", :consumer_secret => "xxxxxxxxxxxxxxxxx" )
@rtoken = @auth.request_token :oauth_callback => @callback_url
@token = @rtoken.token
@secret = @rtoken.secret
@link = @rtoken.authorize_url
session['token' ] = @token
session['secret'] = @secret
redirect_to @link
end
def auth
@auth.authorize_from_request(session[:rtoken], session[:rsecret], params[:oauth_verifier])
end
end
非常相似的方式,但是使用 Twitter gem,并且直接使用 OAuth gem 相同。不管怎样,OAuth::Consumer::token_request 都会因 401 错误而终止。
因此,出于绝望,我尝试 git clone Snitter,添加我的 Twitter 信用,并尝试一下,但它也因 401 而死掉。
我尝试使用 localhost:300/twitter/auth, http://dev.twipler.com:3000/twitter/auth,以及前 2 个的 bit.ly。没有任何效果。
有什么帮助吗?
编辑:当然,我会忘记做最合乎逻辑的事情并删除我的秘密。 (它们已经改变了;))。
xI've been working for days to get Twitter to authenticate with Ruby, but I'm not having any luck.
My first attempt was something like this:
class TwitterController < ApplicationController
def index
@callback_url = "http://dev.twipler.com:3000/twitter/auth"
@auth= TwitterOAuth::Client.new( :consumer_key => "xxx", :consumer_secret => "xxxxxxxxxxxxxxxxx" )
@rtoken = @auth.request_token :oauth_callback => @callback_url
@token = @rtoken.token
@secret = @rtoken.secret
@link = @rtoken.authorize_url
session['token' ] = @token
session['secret'] = @secret
redirect_to @link
end
def auth
@auth.authorize_from_request(session[:rtoken], session[:rsecret], params[:oauth_verifier])
end
end
And a very similar way but with the Twitter gem, and the same with the OAuth gem directly. No matter what OAuth::Consumer::token_request dies with a 401 error.
So, out of desperation I attempted to git clone Snitter, add my Twitter creds, and try it, but it too dies with a 401.
I've tried using localhost:300/twitter/auth, http://dev.twipler.com:3000/twitter/auth, and a bit.ly for each of the former 2. Nothing works.
Any help?
EDIT: Of course I would forget to do the most logical thing to do and delete my secrets. (They've been changed ;)).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想要编辑您的消费者秘密。这样,任何人都可以代表您的应用程序发出请求。
也就是说,请确保您的系统时间已同步到 ntp 服务器。如果您的系统时间漂移过快或过慢,OAuth 请求将会失败,因为它们包含时间戳和相对较短的 TTL。不久前我遇到了这个确切的问题。
如果失败,您可以破解 oauth gem 并打开 HTTP 调试,这将向您显示完整的 HTTP 事务,包括返回的任何错误消息。
You may want to edit your consumer secret out. With that, anyone can make requests on behalf of your app.
That said, make sure your system time is synced to an ntp server. If your system time has drifted fast or slow, OAuth requests will fail, since their include a timestamp and relatively short TTL. I had this exact problem a while back.
Failing that, you can crack open the oauth gem and turn on HTTP debugging, which will show you the full HTTP transaction including any error message returned.