Method: FBCLI.get_access_token
- Defined in:
- lib/fbcli/auth.rb
.get_access_token(app_id, auth_code, app_secret, redirect_uri) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fbcli/auth.rb', line 71 def self.get_access_token(app_id, auth_code, app_secret, redirect_uri) # The redirect_uri doesn't play the same role as in capturing the auth code, however # it must match the one used in the previous case, otherwise the server will reject # the request. # # See: https://www.oauth.com/oauth2-servers/access-tokens/authorization-code-request/ auth_uri = "https://graph.facebook.com/v#{API_VERSION}/oauth/access_token?" + "client_id=#{app_id}" + "&redirect_uri=#{redirect_uri}" + "&client_secret=#{app_secret}" + "&code=#{auth_code}" res = Net::HTTP.get_response(URI.parse(auth_uri)) res = JSON.parse(res.body) res["access_token"] end |