开发者

Getting a 401 oauth_signature error when trying to get an request token from Evernote using OAuth

开发者 https://www.devze.com 2023-02-10 04:07 出处:网络
I am trying to get an Evernote requ开发者_如何学JAVAest token using the OAuth gem with Ruby on Rails:

I am trying to get an Evernote requ开发者_如何学JAVAest 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?


Change site url to use https - I had the same issue.


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.

consumer = OAuth::Consumer.new(consumerKey, consumerSecret, {
        :site => "https://sandbox.evernote.com/", 
        :request_token_path => "/oauth", 
        :access_token_path => "/oauth", 
        :authorize_path => "/OAuth.action"})

requestToken = consumer.get_request_token(
        :oauth_callback => "http://www.me.com/callback")

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.


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.

0

精彩评论

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