SameShirtEveryDay.com

Personal blog of the one called Alex Gorbatchev, from Toronto, Canada.

Hello Facebook in Rails

Posted on August 17th, 2007 by Alex Gorbatchev. In Rails, Web Development.

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.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

12 comments.

  1. 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

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

    before_filter :require_facebook_login

  3. matt

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

  4. 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.

  5. Alex Gorbatchev

    @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.

  6. Rainer

    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

  7. Alex G

    @ Rainer,

    facebook is byoh - bring your own hosting.

  8. Chandoo..

    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.

  9. Oleg

    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

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> , rel="nofollow" in use - no link dropping, no keywords or domains as names; do not spam, and do not advertise!

home
Subscribe to this blog Follow me on Twitter My bookmarks on Delicious My photography on Flickr