Created
April 25, 2019 03:40
-
-
Save troyswanson/8328dfaa04f2aef2e42683ac7c603620 to your computer and use it in GitHub Desktop.
Facebook Photo Downloader
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
import requests | |
import urllib | |
def get_photos(access_token, url='https://graph.facebook.com/v2.10/me/photos?fields=images,from'): | |
r = requests.get(url, headers={'Authorization': 'Bearer %s' % (access_token)}) | |
payload = r.json() | |
data = payload['data'] | |
for photo in data: | |
print '>>> %s' % (photo['from']) | |
print '>>> Downloading %s' % (photo['id']) | |
urllib.urlretrieve(photo['images'][0]['source'], '%s.jpg' % (photo['id'])) | |
next_req = payload['paging'].get('next', None) | |
if next_req != None: | |
get_photos(access_token, next_req) | |
get_photos(ACCESS_TOKEN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment