Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Long Lived User Tokens #392

Closed
wants to merge 16 commits into from
28 changes: 28 additions & 0 deletions facebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,34 @@ def get_app_access_token(self, app_id, app_secret, offline=False):
return self.request("{0}/oauth/access_token".format(self.version),
args=args)["access_token"]

def get_long_lived_token(self, app_id, app_secret):
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this exactly the same as the extend_access_token method?

"""
Gets a long lived access token.
This method uses a pre-existing short lived user access token and
exchanges it for a long lived user access token.
"""
args = {'grant_type': 'fb_exchange_token',
'client_id': app_id,
'client_secret': app_secret,
'fb_exchange_token': self.access_token}

return self.request("{0}/oauth/access_token".format(self.version),
args=args)

def get_long_lived_token_code(self, app_id, app_secret, redirect_uri):
"""
Gets a code to be exchanged for a long lived token.
Uses a pre-existing server side long lived token to return a code
that can be redeemed for a client side long lived token.
"""
Copy link
Member

Choose a reason for hiding this comment

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

This docstring suffers from the same issues as the description in the documentation.

args = {'access_token': self.access_token,
'client_id': app_id,
'client_secret': app_secret,
'redirect_uri': redirect_uri}

return self.request("{0}oauth/client_code".format(self.version),
args=args)["code"]

Copy link
Member

Choose a reason for hiding this comment

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

If a GraphAPIError has been raised, why are we calling extend_access_token here? Why isn't the code object generated here returned?

def get_access_token_from_code(
self, code, redirect_uri, app_id, app_secret):
"""Get an access token from the "code" returned from an OAuth dialog.
Expand Down