开发者

Get access token request failed with OAuth::Unauthorized 401 problem in Rails

First of all, I am trying to connect my app with an site in China. I am not sure if that matters, it shouldn't since that site fully supports Oauth.

Here is my code.

First step:

  require 'oauth'


   def consumer
     OAuth::Consumer.new("206506xxxx", "574705f63783xxxaa4a0bd35e34390fb", :site =>"http://api.t.sina.com.cn")
    end


 def request_token

    @request_token = consumer.get_request_token
  session[:request_token] = @request_token
    session[:request_token_secret] = @request_token.secret
 redirect_to @request_token.authorize_url(:oauth_callback => 'http://localhost:3000/accesstoken')

 end

It worked well, I was able to go to authorize_url and get an 开发者_如何学Coauth_verifier

However, I encountered an issue when I was trying to get the access token.

 def access_token
 request_token = OAuth::RequestToken.new(
  consumer,
  session[:request_token],
  session[:request_token_secret]
)


access_token = request_token.get_access_token(:oauth_verifier=>params["oauth_verifier"])


 end 

I also tried

   access_token = request_token.get_access_token

But they both returned 401 error.

I cleaned the session so it's probably not due to session expiry

Any Ideas?


I solved the problem myself, so instead of using

  session[:request_token] = @request_token

I used

   session[:request_token] = @request_token.token 

which worked.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜