2

在用户授权应用程序后,我的 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

我浪费了将近一天的时间来修复它,并寻找解决方案,但到目前为止还没有运气。

4

1 回答 1

3

第1步、第2步、第3步都可以

第 4 步:当用户授权您的应用程序时,它将在画布 url 处重定向到 yourapp.com(canvas url),您将执行以下操作:

<script>
window.top.location='https://apps.facebook.com/yourapp' //(canvas page)
</script>

第 5 步:当您的画布页面被调用时,您将signed_request使用您的 fb api 来解析它。

于 2011-10-20T07:46:02.797 回答