-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_access_token.py
30 lines (24 loc) · 1.01 KB
/
get_access_token.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sys # for command line arguments
import requests
def file2string_list(filepath):
with open(filepath, 'r') as file:
lines = file.readlines()
for line in lines:
line = line.replace('\n', '').strip()
return lines
def get_app_access_token(app_id, app_secret):
payload = {'grant_type': 'client_credentials', 'client_id': app_id, 'client_secret': app_secret}
file = requests.post('https://graph.facebook.com/oauth/access_token?', params = payload)
#print file.text #to test what the FB api responded with
result = file.text.split("=")[1]
#print file.text #to test the TOKEN
return result
if __name__ == "__main__":
print("Fetching access token for app...")
app_id, app_secret = file2string_list(sys.argv[1])
access_token = get_app_access_token(app_id, app_secret)
with open('access_token.txt', 'w') as outfile:
outfile.write(access_token)
outfile.close()
print("Finished fetching access_token for app.")
sys.exit(0)