重定向 Facebook“offline_access”权限页面
我正在尝试在使用 Facebook Java API 编码的 iFrame Facebook 应用程序中获得用户对“offline_access”的许可。我了解在用户批准我的申请后我需要获取“无限期会话密钥”。目前,我可以完成我想要的事情,但以一种非常尴尬的方式可能是不正确的。必须有更好的方法来做到这一点。任何想法/想法将不胜感激!
我所做的
在我的应用程序的 servlet 中,我检查用户当前是否具有“offline_access”权限。如果他们这样做,我会通过 Permission.authorizeUrl(Permission.OFFLINE_ACCESS)
获取 URL。然后,我调用response.redirect来访问权限页面。我遇到的两个问题是:
- 重定向的权限页面显示在 iFrame 中。因此,Facebook 图书主菜单栏等会显示两次。即看起来一个应用程序嵌入到另一个应用程序中。
- 一旦重定向到那里,用户将“卡在”权限页面上。除非用户手动返回到我的应用程序中的页面,否则我将无法获取“无限期会话密钥”(通过调用
client.getCacheSessionKey
)。
可能的解决方法?
- 有没有办法在新窗口中打开/重定向到权限页面?这样也许我可以在我的 servlet 中拥有一个线程来继续检查重定向后是否设置了权限。然后我可以在获得“无限期会话密钥”后将其存储在某个地方?
- 有没有办法设置 Facebook 在设置权限后可以访问的 URL? (很像预验证和后验证 URL 设置?)或者在访问权限页面后以某种方式进行控制?
- 也许还有其他方法来设置我的应用程序?作为一个新手,我的想法可能完全错误......
I am trying to get users' permission for 'offline_access' in an iFrame Facebook application coded with the Facebook Java API. I understand that I need to obtain an 'indefinite session key' after the users approves my application. Currently, I can accomplish what I want, but in a very awkward way that is probably not correct. There must be a better way to do this. Any thoughts/ideas would be appreciated!!
What I've done
In a servlet of my app, I check to see if the user currently has 'offline_access' permission. If they do, I get the url by Permission.authorizeUrl(Permission.OFFLINE_ACCESS)
. I then call response.redirect
to get to the permissions page. Two problems I'm having are:
- The redirected permissions page is displayed within the iFrame. Hence, the Facebook book home menu bar etc. are displayed twice. i.e. looking like an app is embedded in another app.
- The user will be 'stuck' on the permission page once redirected there. I won't be able to obtain the 'indefinite session key' (by calling
client.getCacheSessionKey
) unless the user goes back to a page in my app manually.
Possible Work-arounds??
- Is there a way to open/redirect to the permissions page in a new window? That way maybe I can have a thread in my servlet to keep checking whether the permission is set after the redirection. And then I can get the 'indefinite session key' once I have it and store it somewhere?
- Is there a way to set an URL for Facebook to go to after permission is set? (much like the pre-auth and post-auth URL settings?) Or somehow take control after the permission page is hit?
- Any other ways to setup my app maybe?? Being a newbie, I might've totally gotten the idea wrong...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用
fb:promot-permission
XFBML 中的 > 标记?这似乎是获得许可的最简单方法,并且 XFBML 相当容易设置。Have you tried using the
fb:promot-permission
tag in XFBML? That would seem the simplest way of getting the permission granted, and XFBML is fairly easy to set up.