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"}>