Last active
February 6, 2021 22:23
-
-
Save aparrish/4683917 to your computer and use it in GitHub Desktop.
simple python script to fetch an access token for a Facebook application (not a user 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
# fetch an access token for a Facebook application | |
# | |
# run like so: | |
# | |
# $ python facebook_app_token.py --app_id=<your app id> --secret=<your secret> | |
# | |
# ... where <your app id> is your Facebook application ID, and <your secret> | |
# is the application secret for that application (both can be retrieved from | |
# the Facebook developer app) | |
import urllib | |
def fetch_app_access_token(fb_app_id, fb_app_secret): | |
resp = urllib.urlopen( | |
'https://graph.facebook.com/oauth/access_token?client_id=' + | |
fb_app_id + '&client_secret=' + fb_app_secret + | |
'&grant_type=client_credentials') | |
if resp.getcode() == 200: | |
return resp.read().split("=")[1] | |
else: | |
return None | |
if __name__ == '__main__': | |
from optparse import OptionParser | |
parser = OptionParser() | |
parser.add_option('--app_id', dest='fb_app_id') | |
parser.add_option('--secret', dest='fb_app_secret') | |
(options, args) = parser.parse_args() | |
print fetch_app_access_token(options.fb_app_id, options.fb_app_secret) |
gets me urllib.error.HTTPError: HTTP Error 500: Internal Server Error
so for what the script?
you can get access toking by this ??
Seems like issue patched.
How can I get user access_token using the same technique?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can i get a user token using a parser like this?