Method: Koala::Facebook::OAuth#generate_client_code
- Defined in:
- lib/koala/oauth.rb
#generate_client_code(access_token) ⇒ Object
Generates a ‘client code’ from a server side long-lived access token. With the generated code, it can be sent to a client application which can then use it to get a long-lived access token from Facebook. After which the clients can use that access token to make requests to Facebook without having to use the server token, yet the server access token remains valid. See developers.facebook.com/docs/facebook-login/access-tokens/#long-via-code
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/koala/oauth.rb', line 150 def generate_client_code(access_token) response = fetch_token_string({:redirect_uri => @oauth_callback_url, :access_token => access_token}, false, 'client_code') # Facebook returns an empty body in certain error conditions if response == '' raise BadFacebookResponse.new(200, '', 'generate_client_code received an error: empty response body') else result = MultiJson.load(response) end result.has_key?('code') ? result['code'] : raise(Koala::KoalaError.new("Facebook returned a valid response without the expected 'code' in the body (response = #{response})")) end |