Last active
September 9, 2019 22:36
-
-
Save micheleberardi/9c99d86feb6b30de7d45b06b276384e9 to your computer and use it in GitHub Desktop.
Permanent Page Token
This file contains hidden or 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 | |
user_long_token = 'EAAHR3c1UymABABifeBxaSxYBQZBLaEqOFZBAnXlHrF9aYOJZAbs4QBZBcULQTC2uNwPylWf2pZBoZBoZAio0AgBQfG8YRd3hYMUIWnrHf4IoZA5ZAlgYqoVbZA27ucCXzeZCfTeNiwYecM48xXkKgHViJkAqorHeYZByhd7aUQQPP9NqzAZDZD' | |
graph = facebook.GraphAPI(access_token=user_long_token, version="3.1") | |
pages_data = graph.get_object("/me/accounts") | |
print(pages_data) | |
""" | |
RESPONSE WILL BE SOMETHING LIKE THAT | |
{'data': [{'access_token': 'EAAHR3c1UymABAN6W47KDb08KLUcbNq8zJidVO4MJTx1SAZC{ | |
'data': [ | |
{ | |
'access_token': 'EAAHR3c1UymABAN6W47KDb08KLUcbNq8zJidVO4MJTx1SAZCmAF6VqR92jesPIQt773U5ZCBxvnTE0HQC8t2HS8j1ctnZCvvqLIacKRLM6FhhLHNgf9Sqne61QIJ31Nt5MTI85rbm8xnHfAY7oabcfv6Oh3SWqLYDRLVn9dmwwZDZD', | |
'category': 'Blogger', | |
'category_list': [ | |
{ | |
'id': '361282040719868', | |
'name': 'Blogger' | |
} | |
], | |
'name': 'Mikeapicalls', | |
'id': '102927594431953', | |
'tasks': [ | |
'ANALYZE', | |
'ADVERTISE', | |
'MODERATE', | |
'CREATE_CONTENT', | |
'MANAGE' | |
] | |
} | |
], | |
'paging': { | |
'cursors': { | |
'before': 'MTAyOTI3NTk0NDMxOTUz', | |
'after': 'MTAyOTI3NTk0NDMxOTUz' | |
} | |
} | |
}mAF6VqR92jesPIQt773U5ZCBxvnTE0HQC8t2HS8j1ctnZCvvqLIacKRLM6FhhLHNgf9Sqne61QIJ31Nt5MTI85rbm8xnHfAY7oabcfv6Oh3SWqLYDRLVn9dmwwZDZD', 'category': 'Blogger', 'category_list': [{'id': '361282040719868', 'name': 'Blogger'}], 'name': 'Mikeapicalls', 'id': '102927594431953', 'tasks': ['ANALYZE', 'ADVERTISE', 'MODERATE', 'CREATE_CONTENT', 'MANAGE']}], 'paging': {'cursors': {'before': 'MTAyOTI3NTk0NDMxOTUz', 'after': 'MTAyOTI3NTk0NDMxOTUz'}}} | |
""" | |
""" | |
page_id is 102927594431953 | |
""" | |
page_id = '102927594431953' | |
page_token = None | |
for item in pages_data['data']: | |
if item['id'] == page_id: | |
page_token = item['access_token'] | |
print(page_token) | |
""" | |
OUTPUT WILL BE | |
EAAHR3c1UymABAM8sO1GLiHh4GsitGjtxor6LsUDfvpi7nJytbrkCEuFc6KUKFbKTxGlBnqjDE80juYN0Tkv7eEcZCMt2Cs19XlmPVjkanyZCkQ9lHbiQZBZBTpy1oNDNYwbK2VKjO8MMYAlOIRVVAyYWJP7gG5hD8D5pualhcAZDZD | |
""" | |
graph = facebook.GraphAPI(access_token=page_token, version="2.7") | |
print(graph.get_object(id=page_id, fields='about, category')) | |
""" | |
{'about': 'Michelone', 'category': 'Blogger', 'id': '102927594431953'} | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment