Facebook iframe 应用程序在用户授权后被重定向到画布之外

发布于 2024-12-10 22:21:40 字数 1186 浏览 0 评论 0原文

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

我已经浪费了几乎一天的时间来尝试修复它,并寻找解决方案,但到目前为止还没有什么进展。

My facebook app is being redirected to the canvas url (http://my-domain/app) after the user has authorized the app. The sequence of steps is described below:

1) A new user opens the app in canvas and is redirected to oauth permissions dialog via Javascript redirection

2) Once the user has authorized the app, the redirect_uri of the app is called and I get the access token which I save in session

3) I also get the user id of the authorized user and save it to session

4) When I redirect it to the canvas url, it moves out of the facebook canvas

5) If I try to redirect it to the canvas page (http://apps.facebook.com/app_name) it gets stuck in an infinite loop because the session values are cleared and the process is repeated - I don't know why.

It is a rails 3 app and I am using koala gem. The code is shown below:

  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

I have wasted almost a day trying to fix it, and searching for a solution, but no luch as of now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一曲琵琶半遮面シ 2024-12-17 22:21:40

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

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

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

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

Step 1, Step 2, Step 3 are ok

Step 4: When the user authorize your app, it will be redirected to yourapp.com (canvas url)
at canvas url, you'll do:

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

step 5: as your canvas page is called you'll get signed_request then with your fb api you'll parse it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文