python flickrapi下载所有专辑

时间:2017-08-31 20:45:30

标签: flickr

我正在使用flickrapi下载相册并编写了此代码:

flickr = flickrapi.FlickrAPI(api_key, api_password, format='parsed-json')
userid = 'XXXXXXXXX'

# auth and token not required anymore, since already cached       
#flickr.authenticate_via_browser(perms='read')
#token = flickr.get_request_token()

photos = flickr.photos.search(user_id=userid, per_page='100')
sets = flickr.photosets.getList(user_id=userid)

#print photos
#print sets

total_photos=0
for photoset_index in sets['photosets']['photoset']:
    photoset_title = photoset_index['title']['_content']
    number_photos = photoset_index['photos']
    total_photos=total_photos+number_photos
    #print photoset_title,number_photos
total_number_of_albums = len(sets['photosets']['photoset'])
print total_number_of_albums

for photos_index in photos['photos']['photo']:
    photo_name = photos_index['title']
    photo_id = photos_index['id']
    #print photo_name, photo_id
total_number_of_pics = photos['photos']['total']
print total_photos, total_number_of_pics

我可以获取相册的名称和照片数量,但如何访问相册图片?文档和开发人员api没有说明下载。 https://www.flickr.com/services/api/

1 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法。你需要

sudo pip install flickr_download

文档为https://pypi.python.org/pypi/flickr_download

将代码的输出复制到bash脚本中并运行。将下载所有专辑。

以下是代码:

api_key = 'GET_IT_FROM_UR_FLICKR_ACCOUNT'
api_secret = 'GET_IT_FROM_UR_FLICKR_ACCOUNT'

flickr = flickrapi.FlickrAPI(api_key, api_secret, format='parsed-json')
flickr.authenticate_via_browser(perms='read')
print flickr.token_cache.token

photos = flickr.photos.search(user_id=userid, per_page='100') 
sets = flickr.photosets.getList(user_id=userid)

#print photos
#print sets

total_photos=0
for photoset_index in sets['photosets']['photoset']:
    photoset_title = photoset_index['title']['_content']
    number_photos = photoset_index['photos']
    id = photoset_index['id']
    total_photos=total_photos+number_photos
    print "flickr_download -k " + api_key + " -s " + api_secret + " -t -d " + id
    #print id,photoset_title,number_photos
total_number_of_albums = len(sets['photosets']['photoset'])
print total_number_of_albums

for photos_index in photos['photos']['photo']:
    photo_name = photos_index['title']
    photo_id = photos_index['id']
    #print photo_name, photo_id
total_number_of_pics = photos['photos']['total']
# Cross check pics in photoset and actual number of pics. Should be equal
print total_photos, total_number_of_pics