用户授权后,Facebook的iframe应用程式被重定向到画布外 [英] Facebook iframe app being redirected out of canvas after user authorization
问题描述
在用户授权应用程序后,我的Facebook应用正在重定向到画布网址(http:// my-domain / app)。步骤的步骤如下所述:
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)新用户在画布中打开应用程序,并通过Javascript重定向重定向到oauth权限对话框
1) A new user opens the app in canvas and is redirected to oauth permissions dialog via Javascript redirection
2)一旦用户授权了应用程序,就会调用该应用的redirect_uri,并获得我在会话中保存的访问令牌
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)我也得到授权用户的用户ID并将其保存到会话
3) I also get the user id of the authorized user and save it to session
4)当我将其重定向到画布网址时,它移出Facebook画布
4) When I redirect it to the canvas url, it moves out of the facebook canvas
5)如果我尝试将其重定向到画布页面(http://apps.facebook.com/app_name),它会陷入无限循环,因为会话值被清除,重复过程 - 我不知道为什么。
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.
这是一个rails 3应用程序,我使用的是koala gem。代码如下所示:
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.
推荐答案
步骤1,步骤2,步骤3 可以
步骤4:当用户授权您的应用程序时,它将被重定向到yourapp.com(画布网址)
在画布网址,您可以:
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>
步骤5:当您的画布页面被调用时,您将获得 signed_request
然后用你的fb api你会解析它。
step 5: as your canvas page is called you'll get signed_request
then with your fb api you'll parse it.
这篇关于用户授权后,Facebook的iframe应用程式被重定向到画布外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!