to run this example, you need at first a facebook app. this video shows the simple setup. pick the App ID and App Secret from there and insert it in the python code below.
the program returns all comments from a single facebook post. you can limited the request and you can change the facebook post ID. the graph api explorer is the perfect starting point to learn more about the fb api.
the last part is for error handling and simple json parsing to get all the interesting information.
# -*- coding: utf-8 -*-
from json import loads
from urllib2 import Request, urlopen, URLError, HTTPError
APPID = "XXXXXXXXXXXXXXXXXX"
APPSECRET = "XXXXXXXXXXXXXX"
FBPOSTID = "588013424601016"
LIMIT = 3000
GRAPH_URL = "https://graph.facebook.com/%s/comments?access_token=%s|%s&limit=%d" % (
response = urlopen(GRAPH_URL)
except HTTPError as e:
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
except URLError as e:
print 'We failed to reach a server.'
print 'Reason: ', e.reason
decoded = loads(response.read())
for item in decoded['data']:
print '%s,%s,%s' % (
Next Page »