问题
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])
回答1:
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.
来源:https://stackoverflow.com/questions/8279526/deep-link-into-a-facebook-canvas-app