How to Create a Facebook Invite for a Web App

Wolox Engineering
Wolox
Published in
2 min readJan 23, 2015

In this post, I will explain you how to create Facebook invites for web apps. This is mainly because Facebook does not allow invites for web apps, it only allows invites for games, IOS and android apps. Then, a “hack” had to be made for this to be possible.

Here goes the easy part, just create the facebook app! Once you are done with that, add it to the “App in facebook” platform. For this you will need to fill in the following fields: “Web address for the facebook app” and “Secure Canvas URL”. The main and only difference between these two URLs prevails in the fact that the Secure Canvas contains HTTPs. What Facebook does with this is hitting the app through this URL that we are providing.

In this way, it will immediately charge our app into an iframe but this won’t work if a web app is detected. The “hack” that needs to be done is as follows:

If, for example, we are using the following URL

http://www.misitio.com/fb_invite/

In our view fb_invite.html

top.location.href = location.protocol + “//” + location.host;

And in our controller containing the action fb_invite add

def fb_invite
render layout: false
end

An extra tip I would suggest, (I’m not sure if it’s because of my project’s configuration or it has to be done in any case), is to place the following code in our controller:

before_filter :allow_iframe_requests, only: :fb_invitedef allow_iframe_requests
response.headers.delete(‘X-Frame-Options’)
end

And in the view:

= csrf_meta_tags

Anyway, the important “trick” is to force the view that Facebook charges in the iframe to redirect it directly to our app by using top.location.href.

I hope you find this “hack” useful!

Posted by Mariano Matayoshi (mariano.matayoshi@wolox.com.ar)

www.wolox.com.ar

--

--