[Facebooker-talk] Dynamically setting api/secret keys: a quick howto

Robert Matei rmatei at gmail.com
Sat Jan 31 18:50:56 EST 2009


This started out as a request for help, but I figured it out so I figured
I'd share. I run several Facebook apps off a single Rails app and I keep
track of them in the database, so I wanted to set the Facebooker config for
each request, without relying on hard-coded yml files. It's actually pretty
simple:

1) Delete your facebooker.yml file so Facebooker's own initialization
doesn't override your settings.
2) Run something like this <http://pastie.org/376285> as a
prepend_before_filter (might also work as a regular before_filter).

code copied here:
      # replacement for Facebooker.load_configuration - we need this to set
the app
      # dynamically rather than from facebooker.yml.
      def self.set_facebooker_config app = App.current
        puts "Seting Facebooker config for #{app.api_key}..."
        attributes = app.attributes
        ENV['FACEBOOK_API_KEY'] = attributes['api_key']
        ENV['FACEBOOK_SECRET_KEY'] = attributes['secret_key']
        ENV['FACEBOOKER_RELATIVE_URL_ROOT'] = attributes['canvas_page_name']
        ENV['FACEBOOKER_API'] = "new"
        ActionController::Base.asset_host = attributes['callback_url']
      end

Hope this saves someone some diving through the Facebooker source.
Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/facebooker-talk/attachments/20090131/7c68fa19/attachment.html>


More information about the Facebooker-talk mailing list