Specifying facebooker app id by domain
I have a RoR website at domain1.com that uses a facebook application linked to that domain.
I want to make domain2.com to point to the same server as domain1.com, so domain1.com/foo
is equivalent to domain2.com/foo
.
Obviously (I think) I need to make a second facebook application, because the one linked to domain1.com won't work if they visit the site under domain2.com.
However, I don't know how to tell facebooker2, in its facebooker.yml, to use one application if the request comes from one host or a different app if it come开发者_如何学Cs from the other.
Is there any way to do this, or do something that achieves the same result?
Facebooker2 doesn't have built-in support for this, but you can make it support it!
You'll need to override some of the functionality in this file:
facebooker2/lib/facebooker2.rb
Specifically this method:
def self.load_facebooker_yaml
config = YAML.load(ERB.new(File.read(File.join(::Rails.root,"config","facebooker.yml"))).result)[::Rails.env]
raise NotConfigured.new("Unable to load configuration for #{::Rails.env} from facebooker.yml. Is it set up?") if config.nil?
self.configuration = config.with_indifferent_access
end
Change the first line to say:
config = YAML.load(ERB.new(File.read(File.join(::Rails.root,"config","facebooker.yml"))).result)[::Rails.env][::request.domain]
Then add a new level to your facebooker.yml file, something like this:
production:
domain1.com:
app_id: ####
secret: #####
aki_key: #####
domain2.com
app_id: ####
secret: #####
aki_key: #####
development:
localhost:
app_id: ####
secret: #####
aki_key: #####
Let me know how that goes.
精彩评论