深入链接到 Facebook 画布应用程序
我将 Facebook 应用程序 https://example.com
嵌入到 Facebook 应用程序画布中,以便可以在 https://apps.facebook.com/EXAMPLE
上使用它。我的应用程序发送通知电子邮件,其中包含 https://example.com/messages/123
等链接,并且应该打开嵌入到 Facebook 画布中的页面。我该如何实现这一目标?我当前的想法:
- 用户打开
https://example.com/messages/123
- 应用程序检查
signed_request
参数 - 应用程序将用户重定向到
https://apps.facebook.com/EXAMPLE/?requested_page=/messages/123
- 应用程序检查对于
requested_page
参数并重定向到此页面 - 用户看到
https://example.com/messages/123
URL 并嵌入到画布中
是否有更好的模式可以获取这工作?
我的最终工作解决方案(使用 Ruby on Rails)
- 用户打开
https://example.com/messages/123
应用程序在客户端检查是否嵌入了应用程序在画布中:
if(窗口==顶部){ top.location = "https://apps.facebook.com/#{Settings.facebook.app_id}#{request.fullpath}"; }
用户被重定向到
https://apps.facebook.com/EXAMPLE/messages/123
- 应用程序中间件将
POST
转换为GET
如果signed_request
存在(代码和想法借自 https://github.com/dekart/facebooker2/blob/master/lib/facebooker2/rack/post_canvas.rb) 应用程序解析
signed_request
与 fb_graph gemFbGraph::Auth.new(app_id, app_secret, :signed_request => params[:signed_request])
I am embedding a Facebook app https://example.com
into the Facebook app canvas so that it is available at https://apps.facebook.com/EXAMPLE
. My application sends notification emails that contain links like https://example.com/messages/123
and that should open the page embedded into the Facebook canvas. How do I achieve this? My current thoughts:
- User opens
https://example.com/messages/123
- Application checks for
signed_request
parameter - Application redirects user to
https://apps.facebook.com/EXAMPLE/?requested_page=/messages/123
- Application checks for
requested_page
parameter and redirects to this page - User sees
https://example.com/messages/123
URL and is embedded into canvas
Is there a better pattern out there to get this working?
My final working solution (with Ruby on Rails)
- User opens
https://example.com/messages/123
Application checks on client-side if app is embedded in canvas:
if(window == top){ top.location = "https://apps.facebook.com/#{Settings.facebook.app_id}#{request.fullpath}"; }
User is redirected to
https://apps.facebook.com/EXAMPLE/messages/123
- Application middleware converts
POST
intoGET
ifsigned_request
is present (code and idea borrowed from https://github.com/dekart/facebooker2/blob/master/lib/facebooker2/rack/post_canvas.rb) Application parses
signed_request
with fb_graph gemFbGraph::Auth.new(app_id, app_secret, :signed_request => params[:signed_request])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是更新链接以从一开始就指向
http://apps.facebook/example/messages/123
。当您检查身份验证时,只需在授权/登录后设置重定向到同一页面。
无缘无故地将用户重定向到多个页面并不是一个好的做法。
I'd just update the link to point to
http://apps.facebook/example/messages/123
off the start.When you check for authentication just set the redirect after authorization/login to the same page.
Redirecting a user around multiple pages for no reason is just not a good practice.