在用户授权应用程序后,我的 facebook 应用程序被重定向到画布 url (http://my-domain/app)。步骤顺序描述如下:
1) 新用户在画布中打开应用程序并通过 Javascript 重定向重定向到 oauth 权限对话框
2)一旦用户授权了应用程序,就会调用应用程序的redirect_uri,我得到了我保存在会话中的访问令牌
3)我还获得授权用户的用户ID并将其保存到会话
4) 当我将它重定向到画布 url 时,它会移出 facebook 画布
5)如果我尝试将其重定向到画布页面(http://apps.facebook.com/app_name),它会陷入无限循环,因为会话值被清除并且该过程被重复 - 我不知道为什么.
这是一个 rails 3 应用程序,我正在使用 koala gem。代码如下所示:
def index
if (session[:access_token].blank?)
session[:oauth] = Koala::Facebook::OAuth.new(APP_ID, APP_SECRET, oauth_redirect_url)
end
@app_id = APP_ID
end
def redirect
session[:access_token] = session[:oauth].get_access_token(params[:code]) if params[:code]
if session[:access_token].blank?
flash[:error] = "You didn't authorize the application. Please authorize the application to throw a firecracker on your friend's wall!"
redirect_to :action => "authorize_app" and return
else
session[:fb_user_id] = Koala::Facebook::API.new(session[:access_token]).get_object("me")["id"]
end
redirect_to :action => "index"
end
我浪费了将近一天的时间来修复它,并寻找解决方案,但到目前为止还没有运气。