Skip to content

Instantly share code, notes, and snippets.

@lionaneesh
Created September 19, 2015 16:49
Show Gist options
  • Save lionaneesh/a3f98ac9e2015f4ff7d3 to your computer and use it in GitHub Desktop.
Save lionaneesh/a3f98ac9e2015f4ff7d3 to your computer and use it in GitHub Desktop.
Get a list of likes for any facebook post. Ref: http://anee.me/facebook-likes/
import requests
import json
post_id = <POST_ID>
access_token = "<ACCESS_TOKEN>"
template = "https://graph.facebook.com/v2.4/%d?fields=likes&access_token=%s"
url = template % (post_id, access_token,)
likes = []
first = True
while 1:
r = requests.get(url)
result = r.json()
if first:
page_likes = result['likes']
first = False
else:
page_likes = result
likes += page_likes['data']
if ('next' not in page_likes['paging']):
break
url = page_likes['paging']['next']
fp = open("%d_likes.csv" % (post_id), "w")
fp.write("Name,Profile Link\n")
for liker in likes:
fp.write(liker['name'] + "," + "https://facebook.com/" + liker['id'] + "\n")
fp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment