ķ家伙,所以我是用dialybooth API workign和OAauth,所以首先,我不得不直线上升不能存储在会话的OAuth令牌(导轨)
#first redirect the user to the authorize_url
redirect_to dailybooth.authorize_url
#on user return grab the code from the query string
dailybooth.oauth_token(params[:code])
#make request to the api
pp dailybooth.get('/users.json')
问题是,它会不断的重定向,因为它甚至没有检查oauth_token是否被设置,所以我做了这个;现在
unless dailybooth.oauth_token(params[:code])
#first redirect the user to the authorize_url
redirect_to dailybooth.authorize_url
#on user return grab the code from the query string
dailybooth.oauth_token(params[:code])
end
#make request to the api
pp dailybooth.get('/users.json')
,这个送我去dailybooth授权页,授权用户,然后发送到我的网页,我获得了他们的帐户(与返回的用户信息的数组)访问,事情是,如果您刷新的令牌不再存在,并且用户必须重新授权。
于是,我就什么是对的oauth_token存储在会话,
if session[:oauth_code] #If session is set
dailybooth.oauth_token(session[:oauth_code]) #sign in using cookie
else
if params[:code]
@oauth_token_ = params[:code]
session[:oauth_code] = @oauth_token_
else
#first redirect the user to the authorize_url
redirect_to dailybooth.authorize_url
end
end
#make request to the api
@info = dailybooth.get('/users.json')
if @info['error']
if @info['error']['error_code']
if @info['error']['error_code'] == 302 #if getting invalid token, request another token.
session[:oauth_code] = nil
#first redirect the user to the authorize_url
redirect_to dailybooth.authorize_url
end
end
end
我仍然得到同样的事情,当我第一次去我的网站,我重定向到授权页面,当局,然后我可以访问该帐户,但是当我尝试返回索引时,它说oauth_token是无效的。任何帮助?