Building Facebook Applications with Ruby on Rails Zachary Taylor Silicon Valley Ruby on Rails December 13, 2007
Why Facebook? • 50 million+ users, more than 20 million active • Potential for massive viral distribution • Build just for Facebook, or compliment your existing app
Anatomy of an App • Left Nav • Canvas Pages • Profile • Profile Box • Profile Action Links • News Feed • Alerts • Message Attachments • Requests
Other pieces • Product Directory • About • Privacy Settings
Get started • Add the Developer Facebook app • Set up a new application
To set up your app: • Application name • Callback URL • Path to the Facebook app on your server • Canvas page URL • Path on Facebook where your app will live • IFrame or FBML? • Can your application be added on Facebook? • Post-Add URL
FBML vs. Iframe • FBML • Many convenient Facebook-specific tags • Easier to make your app look ‘native’ • Facebook helps with caching • No Javascript, ‘Mock’ AJAX • Can embed Iframe
FBML vs. Iframe • Iframe • Requests to the canvas page are redirected to your server, and displayed in an Iframe • Full CSS and Javascript support • Easy to port existing views • Have to write CSS to mimic Facebook UI • Lack of convenient FBML extensions • Using Iframe makes it easier to port to OpenSocial or other social networks
RFacebook “RFacebook is a Ruby interface to the Facebook API. It hides all the nitty- gritty details behind a beautiful Ruby front-end, allowing you to focus on writing great code.”
RFacebook on Rails A plugin that provides controller, view, model and session extensions, as well as a simple debug panel. • require_facebook_install and require_facebook_login filters • fbsession object can make any API call • ex: fbsession.users_getInfo(:uids => [1234]) • seamless routes: url_for, link_to, etc. are automatically relative to http://apps.facebook.com when it detects that you are in the canvas. • acts_as_facebook_user
Start coding • gem install rfacebook • script/plugin install svn://rubyforge.org/var/svn/ rfacebook/plugins/rfacebook_on_rails • rake facebook:setup • put your API key and your API secret in config/ facebook.yml
The Facebook API • User information • Friend information • Photos • Publish to feed • Notifications • Profile box • And more... (groups, events, marketplace, etc.)
Requiring install • RFacebook on Rails has require_facebook_install and require_facebook_login methods • Require installs rather than just logins. It’s the same amount of friction to the user • Will redirect to an install screen if app is not installed
fbsession • Uses method_missing, can make any API call • Populates common fields for you (api_key, session_key, call_id, etc.), other parameters must be specified. • Use dot syntax for simple data access • response.hpricot to parse XML directly
acts_as_facebook_user • Just add facebook_uid and facebook_session_id to your user model • User.find_or_create_by_facebook_session(fbsession) • Uses method_missing to make API calls • user.first_name, user.pic, user.birthday, etc.
Invites • Limit 20 per user per day • Effective, but challenging to motivate your users to invite their friends • Now you have to use Facebook invite widget • Consider prompting users to invite friends right before the payoff • Consider prompting users to invite friends once a day
Profile box • Always comes up • Surprisingly, one of the most effective viral channels • Build a great profile box • People love clicking on pictures
Notifications • Spam metered • When a user clicks ‘X’, Facebook asks if they want to hide this notifications, all notifications from this app, or if it’s spam. • Consider tracking your own notifications, with a rolling timeout. Never send more than one notification to one user per week/month. • 5 email notifications per user per day
Feeds • 98% of feeds don’t make it • Use feed templates to increase the likelihood that your feeds will be seen • A/B test for effectiveness
Application Directory • Hard to find, hard to navigate, yet it drives a significant number of installs • Take care when naming and describing your app
Be simple! • No if/thens • People love clicking and hate typing • Test the waters for initial viral acceptance, then focus on engagement
Follow the data • A/B Test • Track viral channels individually • Track your app, and keep an eye on fast movers, with Appsaholic • Track your application adds by Facebook referrer from the ‘More Stats’ page.
Links • RFacebook - http://rfacebook.rubyforge.org • Intro at http://livelearncode.com/archives/14 • Tutorial at http://www.liverail.net • http://developers.facebook.com • API docs, FBML docs, Wiki • http://www.facebook.com/developers • Developer community • Create and administer apps here • Subscribe to feeds
Recommend
More recommend