-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetPostLikeUID.py
42 lines (33 loc) · 1.17 KB
/
GetPostLikeUID.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
31
32
33
34
35
36
37
38
39
40
41
42
# Use Python to connect Facebook Graph API
import facebook
import json
import requests
AccessToken = raw_input("Access Token:")
PostID = raw_input("{Post-ID}:")
graph = facebook.GraphAPI(AccessToken)
graphresult = graph.get_object('/' + PostID +'/' + 'likes', fields='id', limit=1000)
# graphresult = graph.get_object('/' + PostID +'/' + 'attending', fields='id', limit=1000)
audiences = list()
while "next" in graphresult["paging"]:
terminate = len(graphresult["data"])
for k in range(0, terminate - 1):
uid = graphresult["data"][k]["id"]
audiences.append(uid)
getnextpageurl = graphresult["paging"]["next"]
nextpage = requests.get(getnextpageurl)
graphresult = json.loads(nextpage.text)
terminate = len(graphresult["data"])
for k in range(0, terminate - 1):
uid = graphresult["data"][k]["id"]
audiences.append(uid)
# print graphresult
print audiences
counts = len(audiences)
print ("Members:" + str(counts))
# dump contents to file:
outputFile = "/Users/cyrix/Desktop/uid.csv"
output = open(outputFile, "w")
print("Dumping to file...")
for i in range(0, len(audiences)):
output.write(str(audiences[i].encode("utf-8", "ignore")) + "\n")
output.close()