如何判断 Tumblr OAuth 凭据是否有效?
使用 ruby OAuth 库,我尝试验证以前用户的凭据是否仍然有效。 (以防他撤销了我的应用程序的权限)我已经为 Twitter 做到了这一点,没有任何问题,因为有一个方便的 .authenticated? Twitter OAuth 库中的方法。但是使用通用库,我找不到类似的方法。
@consumer = OAuth::Consumer.new(
ENV['TUMBLR_CONSUMER_KEY'],
ENV['TUMBLR_CONSUMER_SECRET'],
{ :site => 'http://www.tumblr.com',
:request_token_path => '/oauth/request_token',
:authorize_path => '/oauth/authorize',
:access_token_path => '/oauth/access_token',
:http_method => :get
}
)
@access_token = OAuth::AccessToken.new(@consumer, @tumblrauth['access_token'], @tumblrauth['access_token_secret'])
puts @access_token.inspect
@resp = @access_token.get('api/read')
puts @resp.inspect
当我尝试 @access_token.get() 调用时,我收到服务器错误,关于 nill 没有小写方法的问题,我猜它需要某种字符串。但我不知道它指的是什么参数。
我使用的 access_token 和机密以前可以正常运行,但我撤销了对应用程序的访问权限以测试如何检测它。我只需要某种方法来知道用户不再注册该服务,这样我就可以切换状态。
以下是堆栈跟踪:
NoMethodError - nil:NilClass 的未定义方法“downcase”: /Library/Ruby/Gems/1.8/gems/oauth-0.4.4/lib/oauth/request_proxy/base.rb:93:in 'normalized_uri' /Library/Ruby/Gems/1.8/gems/oauth-0.4.4/lib/oauth/request_proxy/base.rb:113:in 'signature_base_string' /Library/Ruby/Gems/1.8/gems/oauth-0.4.4/lib/oauth/signature/base.rb:77:in 'signature_base_string'
Using the ruby OAuth library, I am trying to verify if a previous user's credentials are still valid. (in case he has revoked privileges to my app) I've done it for Twitter with no problem as there is a handy .authenticated? method in the Twitter OAuth library. Using the generic library though, I can find no similar methods.
@consumer = OAuth::Consumer.new(
ENV['TUMBLR_CONSUMER_KEY'],
ENV['TUMBLR_CONSUMER_SECRET'],
{ :site => 'http://www.tumblr.com',
:request_token_path => '/oauth/request_token',
:authorize_path => '/oauth/authorize',
:access_token_path => '/oauth/access_token',
:http_method => :get
}
)
@access_token = OAuth::AccessToken.new(@consumer, @tumblrauth['access_token'], @tumblrauth['access_token_secret'])
puts @access_token.inspect
@resp = @access_token.get('api/read')
puts @resp.inspect
I get a server error as soon as I try the @access_token.get() call, something about nill not having a downcase method, I'm guessing it's expecting a string of some kind instead. But I don't know what param it's referring to.
The access_token and secret that I'm using were previously functional, but I revoked access to the app to test how to detect that. I just need some way to know that the user is no longer registered with that service, so I can switch the state.
Here is a stack trace:
NoMethodError - undefined method 'downcase' for nil:NilClass:
/Library/Ruby/Gems/1.8/gems/oauth-0.4.4/lib/oauth/request_proxy/base.rb:93:in 'normalized_uri'
/Library/Ruby/Gems/1.8/gems/oauth-0.4.4/lib/oauth/request_proxy/base.rb:113:in 'signature_base_string'
/Library/Ruby/Gems/1.8/gems/oauth-0.4.4/lib/oauth/signature/base.rb:77:in 'signature_base_string'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
按照下面的注释进行编辑:
然后在 @consumer 创建后在控制器中添加以下内容:
注意:这是未经测试的代码,所以 YMMV。
Try:
Edit, as per comments below:
and then in your controller after your @consumer creation, add this:
Note: this is untested code, so YMMV.
在没有用户 Tumblr 用户名的情况下,我可以使其正常工作的唯一方法是使用新的 v2 API。文档在这里: http://www.tumblr.com/docs/en/api/v2< /a>
返回一个小的 JSON 信封,其中包含 200 OK,如果令牌错误,则返回 401 Unauthorized。
现在我必须弄清楚如何获取用户的博客名称,因为您似乎无法再发布到默认博客。幸运的是,您可以同时使用 v2 和 v1 API。
The only way I could get this to work without the user's Tumblr username, is using the new v2 API. Docs here: http://www.tumblr.com/docs/en/api/v2
Returns a small JSON envelope with a 200 OK, or a 401 Unauthorized if the tokens are bad.
Now I have to figure out how to get the user's blog name since you can't seem to post to the default blog anymore. Fortunately, you can use both v2 and v1 APIs at the same time.