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...
Related
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.
I am building a one page Facebook Canvas App using the JS SDK.
Navigation inside the app does not require a new full HTTP request, so I wonder how can I change the "main" facebook URL (http://apps.facebook.com/my_app/[URL]).
All I've been able to do to change the browser URL is call
parent.location.href = 'http://apps.facebook.com/my_app/[SOME_URL]'
but this of course reloads the entire page, and it's not exactly what I want to do. I see lots of unanswered questions about this, is there a JS SDK trick or something like that, since all history/location access from inside the app frame is prohibited for security, or it's just something we'll never be able to do?
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.
I am hosting a Facebook app on Google app engine, I need to make sure the user is logged into facebook before anything.
What I can currently do is display facebook's log in button using fbxml, but I prefer the user would be redirected to Facebook's log in page if he wasn't logged in, then back to my app's main page, this way I can make sure that the user is logged in before doing anything.
I am new to Facebook apps, I read here that I can redirect the user to
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL
in order to authenticate him. But using GAE's self.redirect(url) doesn't work, the page stays the same. I was hoping I could do something like this in my handler:
if u'signed_request' in self.request.POST:
facebook.load_signed_request(self.request.get('signed_request'))
if not facebook.user_id:
self.redirect("https://www.facebook.com/dialog/oauth?"+
"client_id={0}&redirect_uri={1}"
.format(FACEBOOK_APP_ID, EXTERNAL_HREF))
return
but as i said earlier this doesn't work.
I'm assuming by 'Facebook App' you mean a Canvas App - so something that will live at https://apps.facebook.com/YOUR_NAMESPACE from a user perspective?
If so, you'll need to add the redirect via Javascript using window.top, as your app is loaded in an iframe. See https://developers.facebook.com/docs/appsonfacebook/tutorial/ and search for 'top', then view the example toward the end of the page.
There are also good examples on the Php Sdk that facebook provides. I like the with_js_sdk.php example. It runs seamlessly and is good to follow.
https://github.com/facebook/php-sdk
http://developers.facebook.com/docs/reference/php/
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';