Railsconf: Giving Rails the Big F – Surviving Facebook Integration Unscarred, Greg Borenstein

May 6, 2009 Pivotal Labs

The Facebook API Menagerie

Facebook API has many different parts:

Canvas Apps

FB requests from your site, they inline the resonse in the middle of the page.

  • Not available: JavaScript.
  • Available: FBJS – a sandboxed limited JS API, FBML – a templating language, the FB session.

iFrame Apps

Your response is put in an IFRAME on the page.

  • Available: FB session.
  • Not available: FBJS, FBML.

Connect App

Host your app on your own domain.
Connect back into FB to e.g. user their authentication & friends model.

  • Available: Connect Session
  • Not available: FB Session

Pages/Profiles

  • No JS

Think of FB as a browser

FB API LOLZ

  • REST API – api/facebook.com/restserver.php – awesome URL.
  • Facebook does not do GETs, they always POST to your site.
  • Connect inside an iFrame, Connect requires the XHTML doctype to work, but iFrames are not supported in XHTML.

SRSLY

Running your App in development

  1. Create an app
  2. Setup DynDNS.com, point it at your IP address http://mysubdomain.dyndns.com
  3. open ports on your local network
  4. Add /etc/host entry: 0.0.0.0 facebook.dontexist.com

Abstract the API

  • Use Facebooker.
  • apps.facebook.com/facebooker_tutorial
  • Access everything through the session
    if session[:facebook_session]
    @friends = session[:facebook_session].user.friends.collect do |f|
    User.find_by_fb_user_id f.uid
    end

Project your code

e.g. use rack-facebook so everything is not a POST

Others

  • Frakie: Facebooker for Sinatra
  • rack-facebook: tranlates FB POST to correct action

How can I make things better?

  • Need a test harness for session[:facebook_session]. There is something in facebooker that needs extraction.
  • Greg is starting Faceboot API Continouus Integration Suite of Tests – github.com/atduskgreg/FACIST – some JS hooks to green/red light that your tags are actually showing up in the page.

About the Author

Biography

More Content by Pivotal Labs
Previous
Erector 0.6.3 – Now Ready to Conquer The World
Erector 0.6.3 – Now Ready to Conquer The World

[Updated: added instructions "If you are using a widget in rails, you now need to inherit from RailsWidget"...

Next
Railsconf: Rails Metal, Rack and Sinatra – Adam Wiggings (Heroku)
Railsconf: Rails Metal, Rack and Sinatra – Adam Wiggings (Heroku)

Rails Metal Rails Metal is a gateway to the exciting and possibly dangerous world of Rack. Replace selecte...

Enter curious. Exit smarter.

Learn More