Skip to content

Instantly share code, notes, and snippets.

@miquelbeltran
Created October 9, 2012 14:21
Show Gist options
  • Save miquelbeltran/3859127 to your computer and use it in GitHub Desktop.
Save miquelbeltran/3859127 to your computer and use it in GitHub Desktop.
Download all pictures from your facebook albums in subfolders
#Download all pictures from your facebook albums in subfolders
#uses https://github.com/pythonforfacebook/facebook-sdk
import facebook
import os
def download(url, folder):
"""Copy the contents of a file from a given URL
to a local file.
"""
import urllib
webFile = urllib.urlopen(url)
localFile = open(folder + '/' + url.split('/')[-1], 'w')
localFile.write(webFile.read())
webFile.close()
localFile.close()
oauth_access_token = "paste access token here"
graph = facebook.GraphAPI(oauth_access_token)
albums = graph.get_connections("me", "albums")
for album in albums['data']:
photos = graph.get_connections(album['id'], "photos")
albumpath = album['name']
if not os.path.exists(albumpath):
os.makedirs(albumpath)
for photo in photos['data']:
print photo['source']
download(photo['source'], albumpath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment