Robert Matei
2009-Jan-31 23:50 UTC
[Facebooker-talk] Dynamically setting api/secret keys: a quick howto
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>
Mike Mangino
2009-Feb-01 14:06 UTC
[Facebooker-talk] Dynamically setting api/secret keys: a quick howto
Awesome! Thanks for posting. The setup code is really messy so I''m sure that was a pain to figure out. That''s on my todolist for refactoring to simplify. Mike On Jan 31, 2009, at 6:50 PM, Robert Matei wrote:> 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 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 > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk-- Mike Mangino http://www.elevatedrails.com