Constructs a FacebookDesktopSession, calling the API to grab an auth_token.
api_key |
your API key |
api_secret |
your API secret |
quiet |
boolean, set to true if you don’t want errors to be thrown (defaults to false) |
# File lib/facebook_desktop_session.rb, line 44 def initialize(api_key, api_secret, quiet = false) super(api_key, api_secret, quiet) result = remote_call("auth.createToken", {}) @desktop_auth_token = result.at("auth_createToken_response") @desktop_auth_token = @desktop_auth_token.nil? ? nil : @desktop_auth_token.inner_html.to_s end
Activates the session and makes it ready for usage. Call this method only after the user has logged in via the login URL.
# File lib/facebook_desktop_session.rb, line 76 def activate result = remote_call("auth.getSession", {:auth_token => @desktop_auth_token}, true) if result != nil @session_user_id = result.at("uid").inner_html @session_key = result.at("session_key").inner_html @session_secret = result.at("secret").inner_html end end
Activate using the session key and secret directly (for example, if you have an infinite session)
key |
the session key to use |
secret |
the session secret to use |
# File lib/facebook_desktop_session.rb, line 89 def activate_with_previous_session(key, secret) # set the session key and secret @session_key = key @session_secret = secret # determine the current user's id result = remote_call("users.getLoggedInUser") @session_user_id = result.at("users_getLoggedInUser_response").inner_html end
Gets the authentication URL
options.next |
the page to redirect to after login |
options.popup |
boolean, whether or not to use the popup style (defaults to true) |
options.skipcookie |
boolean, whether to force new Facebook login (defaults to false) |
options.hidecheckbox |
boolean, whether to show the “infinite session” option checkbox (defaults to false) |
# File lib/facebook_desktop_session.rb, line 57 def get_login_url(options={}) # options path_next = options[:next] ||= nil popup = (options[:popup] == nil) ? true : false skipcookie = (options[:skipcookie] == nil) ? false : true hidecheckbox = (options[:hidecheckbox] == nil) ? false : true # get some extra portions of the URL optionalNext = (path_next == nil) ? "" : "&next=#{CGI.escape(path_next.to_s)}" optionalPopup = (popup == true) ? "&popup=true" : "" optionalSkipCookie = (skipcookie == true) ? "&skipcookie=true" : "" optionalHideCheckbox = (hidecheckbox == true) ? "&hide_checkbox=true" : "" # build and return URL return "http://#{WWW_HOST}#{WWW_PATH_LOGIN}?v=1.0&api_key=#{@api_key}&auth_token=#{@desktop_auth_token}#{optionalPopup}#{optionalNext}#{optionalSkipCookie}#{optionalHideCheckbox}" end
returns true if this session is completely ready to be used and make API calls
# File lib/facebook_desktop_session.rb, line 100 def ready? return (@session_key != nil and @session_secret != nil and !expired?) end
Used for signing a set of parameters in the way that Facebook specifies: <developers.facebook.com/documentation.php?v=1.0&doc=auth>
params |
a Hash containing the parameters to sign |
# File lib/facebook_desktop_session.rb, line 108 def signature(params) # choose the proper secret signatureSecret = nil unless (params[:method] == "facebook.auth.getSession" or params[:method] == "facebook.auth.createToken") signatureSecret = @session_secret else signatureSecret = @api_secret end # sign the parameters with that secret return signature_helper(params, signatureSecret) end
Generated with the Darkfish Rdoc Generator 2.