Facebook Canvas iFrame 应用程序 - 使用新的 OAuth 协议授权用户
我正在 iFrame 中开发一个新的 Facebook Canvas 应用程序并尝试向用户授权。新的 OAuth api 建议我重定向到以下内容以在我的应用程序中授权用户:
https:// graph.facebook.com/oauth/authorize? client_id=...& redirect_uri=http://www.example.com/oauth_redirect
然而,这会产生一个奇怪的问题,其中一个完整的向用户请求权限的 Facebook 页面在 iFrame 本身内呈现(即 Facebook 内的 facebook)。有谁知道如何使用新的 OAuth API 解决这个问题,因为我不想开始使用旧的 REST API 方法。
I'm developing a new Facebook Canvas application within an iFrame and trying to authorize users. The new OAuth api recommends I do a redirect to the following to authorize a user in my app:
https://graph.facebook.com/oauth/authorize?
client_id=...&
redirect_uri=http://www.example.com/oauth_redirect
However this produces a weird problem where a full Facebook page requesting permissions from the user is rendered within the iFrame itself (i.e. facebook within Facebook). Does anyone know how to solve this with the new OAuth API as I don't want to start using old REST API methods.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
即使我也遇到了同样的问题,并将其发布在 Facebook 论坛上。版主告诉我,这是一个目前还没有解决方案的问题。看看这个帖子 - http://forum.developers.facebook.com /viewtopic.php?id=56590
Even I had the same issue and I posted it in facebook forum. The moderator informed me that it is an issue for which there is no solution as of now. Take a look at this thread - http://forum.developers.facebook.com/viewtopic.php?id=56590
相反,我找到了解决这个问题的方法,我在我的博客文章 此处。一探究竟。
On the contrary, I have found a solution to this problem that I have outlined in my blog post here. Check it out.
还有另一种方法可以使用 oAuth v2 来完成此操作,这在 facebook 文档中进行了描述,但分为几个页面,因此不容易理解。
首先,您需要在应用程序的“高级参数”中激活“OAuth 2.0 for Canvas”标志。
然后,这是一个 PHP 示例,解释如何处理它:
there is an other way to do it still with oAuth v2, and this is described in the facebook docs, but splitted in several pages, so not easy to understand.
First, you need to activate the "OAuth 2.0 for Canvas" flag ine the "advanced parameters" of you app.
And then, here is a PHP example explaining how to handle it :
试试这篇文章 http://novacoders.blogspot.com/ 2011/04/facebook-apps-oauth-20-authorization.html
如果您不使用任何网络服务器,则需要使用 Javascript SDK。 FB.init() 返回所有必需的数据,例如 access_token。
Try this article http://novacoders.blogspot.com/2011/04/facebook-apps-oauth-20-authorization.html
If you don't use any web server you need to use Javascript SDK. FB.init() returns all necessary data like access_token.
过去两天一直在努力解决这个问题,并在 Facebook 开发者论坛。
Have been struggle with this for the past two days and found a hack to this problem on the Facebook developers forum.
您无法在画布 iframe 内执行简单的重定向 302 或 301,因为这只会重定向 iframe 内的内容。 Facebook 建议发送一小段 JavaScript,将
top.location
设置为对话/oauth 页面。clientid
是您的 AppId,redirect_uri
是处理来自身份验证对话框页面的重定向的页面。You cannot do a simple redirect 302 or 301 within the canvas iframe as this will only redirect the content within the iframe. What Facebook recommends is to send a small bit of JavaScript that will set the
top.location
to the dialog/oauth page.clientid
being your AppId andredirect_uri
being the page which handles the redirect from the auth dialog page.