Created
April 19, 2020 05:02
-
-
Save vaibhavpandeyvpz/27faf5a5fca35fb6bf798eb7f8f8c05b to your computer and use it in GitHub Desktop.
Use Facebook's Graph API with Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import facebook | |
import os | |
import requests | |
APP_ID = os.getenv('FACEBOOK_APP_ID') | |
APP_SECRET = os.getenv('FACEBOOK_APP_SECRET') | |
LLT_ENDPOINT = 'https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=%s&client_secret' \ | |
'=%s&fb_exchange_token=%s ' | |
def get_long_lived_token(token): | |
response = requests.get(LLT_ENDPOINT % (APP_ID, APP_SECRET, token)) | |
token = response.json() | |
return token['access_token'] | |
def run_app(): | |
slt = '' | |
while len(slt) == 0: | |
slt = input('Please copy-paste the token from Graph Explorer:') | |
slt = slt.strip() | |
llt = get_long_lived_token(slt) | |
api = facebook.GraphAPI(access_token=llt) | |
me = api.get_object('me') | |
print(me) | |
if __name__ == '__main__': | |
run_app() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment