Skip to content

Instantly share code, notes, and snippets.

@nonZero
Last active May 22, 2016 13:18
Show Gist options
  • Save nonZero/bab3480fc6f80a1a46d3a3a3179e140b to your computer and use it in GitHub Desktop.
Save nonZero/bab3480fc6f80a1a46d3a3a3179e140b to your computer and use it in GitHub Desktop.
get access token
import requests
import secrets
URL = "https://graph.facebook.com/oauth/access_token"
r = requests.get(URL, {
'client_id': secrets.APP_ID,
'client_secret': secrets.APP_SECRET,
'grant_type': 'client_credentials',
})
r.raise_for_status()
# print(r.text)
key, value = r.text.split("=")
assert key == "access_token"
with open("TOKEN.txt", "w") as f:
f.write(value)
print("OK")
from pprint import pprint
import facebook
with open("TOKEN.txt") as f:
TOKEN = f.read().strip()
graph = facebook.GraphAPI(access_token=TOKEN, version='2.5')
# o = graph.get_object("DonaldTrump",
# fields="about,website,name,posts{type,message}")
o = graph.get_object("DonaldTrump/posts")
pprint(o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment