/ 27.Jan.2008
this tutorial is currently only for rails, and assumes 2.0.2 or above
you'll need the plugin, so svn it, or, I use piston
piston import svn://rubyforge.org/var/svn/facebooker vendor/plugins/facebooker
There is a rake task for basic setup
rake facebooker:setup
that will create a facebooker.yml file, which you can then fill out with your facebook dev info. the authors also say to create the following:
ActionController::Base.asset_host = "your address"
ENV['FACEBOOKER_RELATIVE_URL_ROOT'] = '/canvas/'
ENV['FACEBOOK_API_KEY'] = 'api key'
ENV['FACEBOOK_SECRET_KEY'] = 'secret key'
which I placed in config/initializers/facebooker.rb
I then added 3 before filters to ApplicationController like this
before_filter :ensure_application_is_installed_by_facebook_user
before_filter :ensure_authenticated_to_facebook
before_filter :get_user
def get_user
@facebook_user = facebook_session.user
@user = User.find_or_create_by_facebook_uid(@facebook_user.uid)
end
the first two are class methods of Facebooker::Session, and its a little redundant two call them as before filters the way I did, as the
source code calls the same thing. It's convenient and matches my style to macro it at the top.
The last filter simply calls the function defined below, which sets the facebook user and the app's user.
You could model them as one, but I choose to keep them apart due to Facebook's privacy regs.
after that, you're pretty much back in familiar territory. the plugin has helper method for views, to call FBML through your view, like this, from my layouts/main.fbml.erb
Hi <%= fb_name(@facebook_user) %>!
thats it for now, more soon
micro theme by seaofclouds, and powered with Mephisto Hosting by hostingrails.com
4 Comments
Sorry, comments are closed for this article.