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. 12 comments!

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.

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