Forums | Admin

Discussion Forums: open-discussion

Start New Thread Start New Thread

 

By: Michael Niessner
RE: not sending api_key or secret [ reply ]  
2007-09-12 22:27
Those instance variables should be marshaled as of revision 67.

By: Michael Niessner
RE: not sending api_key or secret [ reply ]  
2007-09-12 21:55
This is a bug. The root of the problem stems from facebook session not marshalling @api_key and @secret_key.

By: Daniel Choi
RE: not sending api_key or secret [ reply ]  
2007-09-11 19:48
<pre>
ENV['FACEBOOK_API_KEY'] = "[our api key]"
ENV['FACEBOOK_SECRET_KEY'] = "[our facebook application secret]"
require 'facebooker'
require 'facebooker/rails/controller'

module Facebooker
class Session
@@logger = RAILS_DEFAULT_LOGGER
def post(method, params = {})
params[:method] = method
# this is what I changed because the api_key kept turning up nil
params[:api_key] = @api_key ||= self.class.api_key <-- CHANGE
params[:call_id] = Time.now.to_f.to_s unless method == 'facebook.auth.getSession'
params[:v] = "1.0"
@session_key && params[:session_key] ||= @session_key
@@logger.debug("Facebook API call: #{params.inspect}")
@@logger.debug("Facebook secret: #{secret_for_method(method)}")

service.post(params.merge(:sig => signature_for(params)))
end
def secret_for_method(method_name)
@secret_key ||= Facebooker::Session.secret_key <-- CHANGE
end
end
end

</pre>

By: Daniel Choi
not sending api_key or secret [ reply ]  
2007-09-11 19:46
Hi.

First, thanks a lot for writing Facebooker. I appreciate it a lot. My company is using it in Rails for a Facebook canvas application.

Unfortunately, I've been having problems getting the Facebooker to make proper calls to the Facebook API. Specifically, for some reason, it's not sending the api_key or mixing the secret in when it constructs the signature parameter.

I found this out after adding some logging to the Facebooker to monitor the parameters that get sent to the Facebook API.

I put these lines at the end of the environment.rb to register our api key and secret, and also to get some logging output from Facebooker for debugging:

ENV['FACEBOOK_API_KEY'] = "[our api key]"
ENV['FACEBOOK_SECRET_KEY'] = "[our facebook application secret]"
require 'facebooker'
require 'facebooker/rails/controller'

module Facebooker
class Session
@@logger = RAILS_DEFAULT_LOGGER
def post(method, params = {})
params[:method] = method
# this is what I changed because the api_key kept turning up nil
params[:api_key] = @api_key ||= self.class.api_key <-- CHANGE
params[:call_id] = Time.now.to_f.to_s unless method == 'facebook.auth.getSession'
params[:v] = "1.0"
@session_key && params[:session_key] ||= @session_key
@@logger.debug("Facebook API call: #{params.inspect}")
@@logger.debug("Facebook secret: #{secret_for_method(method)}")

service.post(params.merge(:sig => signature_for(params)))
end
def secret_for_method(method_name)
@secret_key ||= Facebooker::Session.secret_key <-- CHANGE
end
end
end


You'll notice that two lines marked CHANGE: These are the lines I had to change (adding the ||= and everything after that until the end of the line) to get the Facebooker to use our api_key and the secret_key, instead of nil. I'm not sure why the api_key and secret kept turning up nil, but such was the case until I made these changes.

After I made these changes, everything seems to be working great.

I'm called the Facebooker code from a Rails controller that contains this line after the class declaration,

include Facebooker::Rails::Controller

and which calls this before_filter before the relevant methods:

before_filter :ensure_authenticated_to_facebook

The method call that kept throwing the API error until I made the two changes above was this:

@friends = facebook_session.user.friends!

Please let me know if this is a bug, or if missed something. Thank you!