Guest User

Untitled

a guest
Jun 25th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. # script for download facebook album images
  2. #Python3.6 require facebook sdk
  3. import facebook
  4. import requests
  5. import shutil
  6.  
  7. access_token = "Your FB access token"
  8. graph = facebook.GraphAPI(access_token=access_token, version="2.7")
  9.  
  10. albums_id = "albums_id"
  11. photos = graph.get_object(id='{}/photos'.format(albums_id), fields="limit=1000,images")
  12.  
  13. save_path = "PATH to save all the image"
  14. for index, photo in enumerate(photos['data']):
  15. img_url = photo['images'][0]['source']
  16. r = requests.get(img_url, stream=True)
  17. if r.status_code == 200:
  18. with open("{}/{}.jpg".format(save_path, index), 'wb') as f:
  19. r.raw.decode_content = True
  20. shutil.copyfileobj(r.raw, f)
Add Comment
Please, Sign In to add comment