新手问题 oauth2 豆瓣好像有问题呀。

metal · 发布于 2013年03月08日 · 1178 次阅读
475
ENV['RACK_ENV'] ||= 'development'

require 'rubygems'
require 'bundler'
Bundler.setup
require 'yaml'
require 'json'
Bundler.require(:default, ENV['RACK_ENV'].to_sym)

class ApplicationCore < Sinatra::Base

  use Rack::Session::Cookie


  set :public_folder => './public'
  set :views => './views'


  def client
    OAuth2::Client.new(APPKEY, SECRET,
    {:site => 'https://api.douban.com',
     :authorize_url => 'https://www.douban.com/service/auth2/auth',
     :token_url => 'https://www.douban.com/service/auth2/token'})
  end



  get '/' do
    erb :index
  end

  get '/auth/douban/connect' do
    puts redirect_uri
    redirect client.auth_code.authorize_url(:redirect_uri => redirect_uri, :scope => 'douban_basic_common,community_basic_note')
  end

  get '/auth/douban/callback' do
    access_token = client.auth_code.get_token(params[:code], :redirect_uri => redirect_uri)
    puts "#{access_token.inspect}"
  end

  def redirect_uri
    uri = URI.parse(request.url)
    uri.path = '/auth/douban/callback'
    uri.to_s
  end

  run! if __FILE__ == $0

end

卡在callback这里。错误信息里我都拿到access_token了,就卡在callback这里出不来

TypeError at /auth/douban/callback
can't convert nil into Integer
...
....
...
...
...
#<OAuth2::Error: {"access_token":"xxxxx","douban_user_name":"kennx9","douban_user_id":"63178469","expires_in":604800,"refresh_token":"xxxxx"}>
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册