-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetfbphotos.py
44 lines (33 loc) · 995 Bytes
/
getfbphotos.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
43
44
#!/usr/bin/env python
import httplib
import json
import urllib
from urllib import urlretrieve
from urllib import urlopen
from urlparse import urlparse
"""
Simple programs to grab profile photos of all friends.
"""
server = 'graph.facebook.com'
myID = 'tpe11etier'
accessToken = 'PUT YOUR TOKEN HERE'
URL = "/tpe11etier/friends?access_token=" + accessToken
def getfriends():
conn = httplib.HTTPSConnection(server)
conn.request("GET", URL)
response = conn.getresponse()
data = response.read()
list = json.loads(data)['data']
IDs = [(friends['id'], friends['name']) for friends in list]
return IDs
def getphotos():
if not os.path.exists("photos"):
os.makedirs("photos")
for id, name in getfriends():
url = "https://graph.facebook.com/" + id + "/picture"
filename = os.path.join("photos", "%s.jpg" % (name))
urlretrieve(url, filename)
def main():
getphotos()
if __name__ == '__main__':
main()