Twitter 的 Ruby OAuth 出现 401 错误

发布于 2024-09-16 01:10:16 字数 1223 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So尛奶瓶 2024-09-23 01:10:16

您可能想要编辑您的消费者秘密。这样,任何人都可以代表您的应用程序发出请求。

也就是说,请确保您的系统时间已同步到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文