Skip to content

Instantly share code, notes, and snippets.

@fordnox
Created February 25, 2015 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fordnox/2dc569f259d06efc279f to your computer and use it in GitHub Desktop.
Save fordnox/2dc569f259d06efc279f to your computer and use it in GitHub Desktop.
Facebook friends pictures
import requests
import json
import urllib2
import webbrowser
from pprint import pprint
token = ''
api_url = 'https://graph.facebook.com/v2.1/'
params = {'access_token' : token}
def extractFriends():
call = "me/friends?fields=picture.width(9999).height(9999).type(large),gender,name"
response = requests.get(api_url + call, params=params)
r = (json.loads(response.content))
#pprint(r)
for f in r['data']:
#print f['name'], f['gender']
p_url = str(f['picture']['data']['url'])
#print p_url
opener1 = urllib2.build_opener()
page1 = opener1.open(p_url)
my_picture = page1.read()
filename = f['name']+"_"+f['id']+".jpg"
print filename+" downloaded..."
fout = open('images/'+filename, "wb")
fout.write(my_picture)
fout.close()
extractFriends()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment