I’ve signed up for Facebook today to check out how the whole application development works. Setting up a development server at home which is accessible from Facebook is pretty straight forward.

Here’s what you need:

  1. Facebook account
  2. Local box with Apache
  3. Domain name pointing to your home IP. I use No-Ip.

Here are the steps I took.

  1. Setting up development application on Facebook. Follow the guide, it’s pretty straight forward.
  2. Set up No-Ip to point *.dev.mydomain.com to my local box. This allows me to create as many Rails applications as I need to.
  3. Configured Apache to forward all calls to fbtest.dev.mydomain.com to localhost:3000 using mod_proxy like so:
    <VirtualHost *:80>
      ServerName fbtest.dev.mydomain.com
      ProxyPass / http://127.0.0.1:3000/
    </VirtualHost>
  4. gem install rfacebook
  5. cd /anywhere/fbtest
  6. rails .
  7. ruby script/plugin install svn://rubyforge.org/var/svn/rfacebook/plugins/rfacebook_on_rails
  8. rake facebook:setup
  9. Go to http://www.facebook.com/developers/apps.php
  10. Copy and paste API key and secret to config/facebook.yml. Set canvas_path to the local path on Facebook, ie /myfacebookapp/ and callback_path to local path on your server, ie /facebook/.
  11. ruby script/generate controller facebook index
  12. Edit index method in Facebook controller, like so:
    class FacebookController < ApplicationController
      def index
        @result = fbsession.friends_get.uid_list
      end
    end
  13. Edit index.rhtml like so:
    <% @result.each do |uid| %>
      <fb:name uid="<%= uid %>" />
    <% end %>
  14. Start Apache
  15. ruby script/server
  16. Now you should be able to hit your Facebook application page at http://apps.facebook.com/myfacebookapp

You should see a list of your friends. Took me about 30 minutes to figure all this out.

12 Responses to “Hello Facebook in Rails”
  1. links for 2007-08-21 « Caiwangqin’s delicious bog Says:

    […] Hello Facebook in Rails (tags: Facebook rubyonrails plugin rfacebook) […]

  2. Ruby on Rails Facebook Says:

    […] Hello Facebook in Rails […]

  3. Matt P Says:

    Thanks for the clean, simple tutorial Alex. I’d like to also note the main documentation is also on the RFacebook homepage:

    http://rfacebook.rubyforge.org

  4. Chris Saylor Says:

    Don’t forget to add this to your controller to actually request login.

    before_filter :require_facebook_login

  5. matt Says:

    can be more details, many of the steps are left out.
    is the app fbml or iframe ?

  6. Bhushan Says:

    Hey Do you know any ways to put google maps in Facebook application I have done it with iframe but with this I dont have access to map object outside the frame .

    Please send me the reply I you have any solution.

  7. Alex Gorbatchev Says:

    @Bhurshan,

    I don’t think you have many options for GMaps. Facebook sandboxes all JS, so you can’t include it straight. If you need to have maps, the only two options i can think of are flash and iframe. You can use flash with Yahoo Maps.

  8. Rainer Says:

    Hello Alex,

    thanks for the tutorial!

    One thing I would like to know, though: Does Facebook provide any kind of hosting service for their members, or are we required to host our rails applications for facebook on our own webspace?

    Kind regards,

    Rainer

  9. Alex G Says:

    @ Rainer,

    facebook is byoh - bring your own hosting.

  10. Chandoo.. Says:

    Hey all,

    Had you done some functionality with the google maps in the FB app. I am using it in my app but not be able to access the object of the map, i am using it in an iframe. Could you suggest me some thing.

  11. Blog.XDite.net » 使用 ROR , 10 分鐘做出一個 facebook app ! Says:

    […] Hello Facebook in Rails […]

  12. Oleg Says:

    The names of my friends are getting displayed by using this code:

    ” />

    If I do following

    it will display uids of all my friends.

    Any idea if I am missing anything?

Leave a Reply