Skip to content

Commit

Permalink
Added method to replace offline_access.
Browse files Browse the repository at this point in the history
You can exchange a short-lived access token for a longer-lived (60 days)
access token.
  • Loading branch information
dpogue committed May 2, 2012
1 parent bd0afbe commit 449341a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/mini_fb.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -518,6 +518,24 @@ def self.oauth_access_token(app_id, redirect_uri, secret, code)
return params return params
end end


# returns a hash with one value being 'access_token', the other being 'expires'
def self.fb_exchange_token(app_id, secret, access_token)
oauth_url = "#{graph_base}oauth/access_token"
oauth_url << "?client_id=#{app_id}"
oauth_url << "&client_secret=#{secret}"
oauth_url << "&grant_type=fb_exchange_token"
oauth_url << "&fb_exchange_token=#{CGI.escape(access_token)}"
resp = RestClient.get oauth_url
puts 'resp=' + resp.body.to_s if @@logging
params = {}
params_array = resp.split("&")
params_array.each do |p|
ps = p.split("=")
params[ps[0]] = ps[1]
end
return params
end

# Return a JSON object of working Oauth tokens from working session keys, returned in order given # Return a JSON object of working Oauth tokens from working session keys, returned in order given
def self.oauth_exchange_session(app_id, secret, session_keys) def self.oauth_exchange_session(app_id, secret, session_keys)
url = "#{graph_base}oauth/exchange_sessions" url = "#{graph_base}oauth/exchange_sessions"
Expand Down

1 comment on commit 449341a

@phwd
Copy link

@phwd phwd commented on 449341a Jan 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is an exchange, though shouldn't the function be called fb_extend_token ?

Please sign in to comment.