Facebook app invites with RoR 6

Posted by Andrew Wed, 19 Sep 2007 20:25:00 GMT

Ray and I spent quite a while to get everything in our Facebook app to work. There were some blog posts about how get invites to work but they are outdated (and they involve some nasty FQLs).

One thing that I did was to create a beta fb application to test all this stuff out with our beta server, this helps a lot.

So in case you’re going crazy adding invites to your fb app, here’s how we did it. Keep in mind that the fb platform changes rapidly so by the time you read this there is probably a better way to do invites.

In your canvas partial, add a link to http://apps.facebook.com/[yourappname]/invite

here’s how our invite method looks like:

  def invite
    @appname = ENV['RAILS_ENV'] == 'production' ? 'onmylist' : 'onmylist_beta'
    @appid = ENV['RAILS_ENV'] == 'production' ? 12345678 : 01234567

    if fbsession.is_valid?
      @friends2exclude = fbsession.friends_getAppUsers.uid_list        
    end

    render :partial => "select_fbml" 
  end

note: app id’s are not real! :)

Here’s the select_fbml partial:

<fb:fbml>
<fb:subtitle>Invite your friends to join OnMyList</fb:subtitle>

<div style="background-color:#f2fbdc;padding-bottom:0;margin-bottom:0">

<% join_button = CGI::escapeHTML "<fb:req-choice url='http://www.facebook.com/apps/application.php?id=#{@appid}' label='Join OnMyList'>" %>

<fb:request-form 
method="POST" 
invite="true" 
type="OnMyList" 
action="http://apps.facebook.com/<%= @appname %>/"
content="Let's join OnMyList so you can list your pants off! <%= join_button %>">

<fb:multi-friend-selector
rows="5"
exclude_ids="<%= @friends2exclude.join(',') %>"
showborder="false" 
actiontext="Here are your friends who don't have OnMyList. Invite them now!">
</fb:request-form>

</div>
</fb:fbml>

the exclude_ids param is to exclude your friends who already have the app installed.