Created
October 9, 2012 14:21
-
-
Save miquelbeltran/3859127 to your computer and use it in GitHub Desktop.
Download all pictures from your facebook albums in subfolders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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