OAuth :: Unauthorized:401在Rails 3.2控制台中使用dropbox-api gem

时间:2013-09-06 06:18:13

标签: ruby-on-rails dropbox-api

我正试图在Rails控制台中使用dropbox-api gem进行授权

以下是我在控制台中解雇的方法:

但是,在通过401 Unauthorized

访问时,我一直遇到oauth_verifier错误

这是我正在使用的宝石:https://github.com/futuresimple/dropbox-api

> Dropbox::API::Config.app_key    = MY_APP_TOKEN
> Dropbox::API::Config.app_secret = MY_APP_SECRET
> consumer = Dropbox::API::OAuth.consumer(:authorize)
> request_token = consumer.get_request_token
> request_token.authorize_url(:oauth_callback => 'http://localhost:3000/callback/dropbox')
> hash = { oauth_token: request_token.token, oauth_token_secret: request_token.secret}
> request_token  = OAuth::RequestToken.from_hash(consumer, hash)
> result = request_token.get_access_token(:oauth_verifier => request_token.token)

ERROR:

1.9.3-p448 :019 > access_token = request_token.get_access_token(:oauth_verifier => request_token.token)
OAuth::Unauthorized: 401 Unauthorized
    from /Users/xiruki/.rvm/gems/ruby-1.9.3-p448/gems/oauth-0.4.7/lib/oauth/consumer.rb:216:in `token_request'
    from /Users/xiruki/.rvm/gems/ruby-1.9.3-p448/gems/oauth-0.4.7/lib/oauth/tokens/request_token.rb:18:in `get_access_token'
    from (irb):19
    from /Users/xiruki/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
    from /Users/xiruki/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
    from /Users/xiruki/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

任何变通办法都将受到赞赏。

1 个答案:

答案 0 :(得分:0)

将我的评论转到答案:

在尝试致电get_access_token之前,请务必访问授权网址并“允许”该应用。