Redirect from Activity post to specific canvas (iframe) page [duplicate] - facebook

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 into GET if signed_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 gem
FbGraph::Auth.new(app_id, app_secret, :signed_request => params[:signed_request])

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.

Related

Single Facebook App multiple Client Facebook Page Tab

I have created a Facebook Application which will be used as a Facebook Tab Page. My problem is that I am unable to get the page id.
I want to use this single application for multiple Facebook Page Tabs but the content will vary based on the Page Id.
The code I am trying to use to get the signed_request is using the JavaScript SDK.
FB.getLoginStatus(function(response) {
console.log(response);
})
This can be done with the signed_request parameter, which is passed on to your URL.
The easiest solution is to use the PHP SDK. It offers a function called "getSignedRequest": https://developers.facebook.com/docs/reference/php/facebook-getSignedRequest
Those are the fields of the signed_request parameter: https://developers.facebook.com/docs/reference/login/signed-request
If you donĀ“t want to use the PHP, you need to parse the parameter on your own. Check out this link for more information and search for "Parsing the Signed Request": https://developers.facebook.com/docs/facebook-login/using-login-with-games
Edit: you will not get the correct signed_request using the JavaScript SDK. Use PHP (or your server language) for this.
The mistake was that the URL added in the Facebook page tab settings was getting redirected as it did not have a "/"; there was a redirect for SEO added and the URL in the Facebook APP sittings did not have the "/".
So as it was getting redirected Facebook sent the POST variable but we have not handled it. Now it is fixed.
Special thanks to #luschn and #Fran Barbero for all your efforts in this.

How to get Facebook to link to my site instead of my application?

I have implemented the Like button (https://developers.facebook.com/docs/reference/plugins/like/) into my pages, along with the proper meta tags. The like text on Facebook is now like:
[[User]] likes [[product_with_link]] on [[site]].
While [[product_with_link]] takes me to link I have liked, [[site]] takes me to the Facebook application, not to the site's main url. Is there a way I can make Facebook redirect to my site and not my Facebook app when clicking on this link?
This is a "limitation" of the requirement to have an application when using the social plugins. It makes it easier to track the insights when they are attached to an application id.
To get a simple workaround up and running, all you have to do is have some code similar to this (example is in PHP) on your main canvas URL for your application.
echo "<script language='javascript'>";
echo "top.location.href = 'http://your.site.com/';";
echo "</script>";
Now as soon as a user lands on your application's canvas, a JavaScript redirect will send them to the appropriate page on your site.
Note that this redirection will also happen for users accessing your canvas URL directly.

Facebook canvas app with rails3

I'm writing facebook canvas application with Rails3 using omniauth-facebook gem. The few moments are not clear:
Rdirect after sing in (in '/auth/facebook/callback' => 'session#create'):
After successful sing_in if user is redirected to root_url it sometime arrives to
my canvas page URL (http://localhost:3000) outside of the frame. On other hand, when
redirecting him to my app url (http://apps.facebook.com/my_app) it sometime stacks on
blank page inside the frame. So how to handle this redirect correctly?
What is a proper way to link between pages inside my app? Currently I use relative links and top.location url is always stay my app url (http://apps.facebook.com/my_app). But I saw that many facebook apps redirect the client top.location (http://apps.facebook.com/my_app/internal_link)... It raises one more question:
Now facebook always fetch my app into the iframe using POST method. How to handle this behavior in RESTful rails application?
I'd very thankful for any advices...

What's the purpose of the Facebook OAUTH2 redirect URL?

I am currently redirecting to this:
https://graph.facebook.com/oauth/authorize?client_id=305384546164461&redirect_uri=http://www.eeisi.com/bridge/auth.php&type=web_server&display=page&scope=publish_stream,%20user_about_me,%20user_likes,%20email
I have no idea why I am required to redirect to the URL specified in my application settings, for my canvas page. The purpose behind this never seems to be mentioned.
So I redirect there, and it asks for permission to use the app... great...
Then it goes to another dialog page, and asks for additional permissions... fine...
AND THEN... it goes to that redirect URL, and then what am I supposed to do?
Am I supposed to create some sort of landing page that redirects back to the canvas page on facebook?
Like...
http://www.eeisi.com/bridge/auth.php <--- the landing page
Am I then supposed to take the resulting auth code:
http://www.eeisi.com/bridge/auth.php?code=(long-fricking-string)
and pass that back to the canvas app page, like so?
http://aps.facebook.com/eebridge/?code=(long-fricking-string)
???
Is that how the whole thing fits together?
You'll want to exchange the code query parameter for an access token.
See step 4 here:
http://developers.facebook.com/docs/authentication/server-side/
You're redirected back to your app, as your app should know the application secret - which you'll need to exchange the code for an access_token.

How to authenticate multiple entry points in a facebook app?

I am using an IFrame application with XFBML and the new Javascript API.
I'd like to have a facebook application with multiple entry points. These will most likely represent different links coming from a fan page tab.
I can do this quite easily if the pages don't require authentication - for instance I can create several pages under the app and if a new user comes I can send them to any page:
http://apps.facebook.com/myapp/offers
http://apps.facebook.com/myapp/game
http://apps.facebook.com/myapp/products
The problem is that if I need to have authentication then once the user is authenticated they get redirected to my default post-authorization url.
Is there a way for a user that comes to /game to stay on /game after they are authenticated without redirecting.
I thought I could do it with the AJAX login form - but I cannot find out how to do that in a Facebook IFrame application.
I think the example using requirelogin only works for FBML.
<a href="http://apps.facebook.com/mysmiley" requirelogin=1> Welcome to my app</a>.
Is there a way to accomplish this with Facebook APIs - or will I have to do some kind of clever cookie handling?
You can use the facebook connect JS library inside of an iframe app and then redirect them to the appropriate url in javascript if they click allow. Best to go to the Facebook dev docs on the Javascript SDK on Fb:login here: http://developers.facebook.com/docs/reference/javascript/
Basically if the login is successful, you will get a callback where you should redirect them in javascript by using window.top.location = 'yoururlhere';