尝试使用 OAuth 从 Evernote 获取请求令牌时出现 401 oauth_signature 错误
我正在尝试使用 OAuth gem 和 Ruby on Rails 来获取 Evernote 请求令牌:
customer = OAuth::Consumer.new("consumer_key_here", "consumer_secret_here",{ :site=>"http://sandbox.evernote.com/",:request_token_path => "/oauth",:oauth_signature_method => "PLAINTEXT" })
@request_token = customer.get_request_token
但我收到此错误
OAuth::Unauthorized in PagesController#home
401 oauth_signature
可能是什么原因导致的?
I am trying to get an Evernote request token using the OAuth gem with Ruby on Rails:
customer = OAuth::Consumer.new("consumer_key_here", "consumer_secret_here",{ :site=>"http://sandbox.evernote.com/",:request_token_path => "/oauth",:oauth_signature_method => "PLAINTEXT" })
@request_token = customer.get_request_token
But I'm getting this error
OAuth::Unauthorized in PagesController#home
401 oauth_signature
What could be causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更改网站 url 以使用 https - 我遇到了同样的问题。
Change site url to use https - I had the same issue.
Evernote 的示例代码现在包含一个使用 OAuth gem 的 Ruby OAuth 示例。您可以从 http://www.evernote.com/about/developer/api 下载示例代码/。
在这种情况下,您需要在获取请求令牌时传递 oauth_callback 参数,因为 Evernote OAuth 提供程序实现了 OAuth 1.0a。
另外,无需将签名方法设置为 PLAINTEXT; Evernote 的提供商支持 HMAC-SHA1,这是 OAuth gem 默认使用的。
Evernote's sample code now contains a Ruby OAuth example that uses the OAuth gem. You can download the sample code from http://www.evernote.com/about/developer/api/.
In this case, you need to pass the oauth_callback parameter when getting a request token, because the Evernote OAuth provider implements OAuth 1.0a.
Also, there's no need to set the signature method to PLAINTEXT; Evernote's provider supports HMAC-SHA1, which is what the OAuth gem uses by default.
您需要将 OAuth 消费者密钥和消费者秘密放入当前显示“consumer_key_here”和“consumer_secret_here”的新方法中。
如果你的真实代码确实有值,请检查并确保它们是正确的——这听起来很愚蠢,但我昨天在使用 OAuth 时遇到了同样的问题,结果发现我使用了错误的变量。
You need to put your OAuth consumer key and consumer secret in the new method where it currently says "consumer_key_here" and "consumer_secret_here".
If you do have values there for your real code, check and make sure they are correct-- it sounds silly, but I had this same problem yesterday with OAuth and it turns out I was using the wrong variables.