简体   繁体   中英

python flickr api for group search and get image data set

Is there any python flickr api where i can hit the group url and get the all the latest image data ?

I have an url like :

https://www.flickr.com/groups/caterpillarequipment/

I want to get all the latest images data set. I try to do it with flickrapi lib but able to figure out any ways till now. I'm new to flickr api dont know how to get this data.

If you want to get all of the info for a group's pool use the flickr.groups.pools.getPhotos API call, like this:

import flickrapi
from pprint import pprint

api_key = 'your api key'
secret = 'your secret key'
flickr = flickrapi.FlickrAPI(api_key, secret, format='parsed-json')

group_id = '544735@N20'    # caterpillarequipment's group_id
response = flickr.groups.pools.getPhotos(group_id=group_id, per_page=3)
pprint(response)
{u'photos': {u'page': 1,
             u'pages': 1033,
             u'perpage': 3,
             u'photo': [{u'dateadded': u'1428715622',
                         u'farm': 8,
                         u'id': u'16912446348',
                         u'isfamily': 0,
                         u'isfriend': 0,
                         u'ispublic': 1,
                         u'owner': u'71639059@N00',
                         u'ownername': u'ocrr4204',
                         u'secret': u'311b63f966',
                         u'server': u'7685',
                         u'title': u'Dufresne Construction 146 a CAT D7H bulldozer Ottawa, Ontario Canada 04252007 \xa9Ian A. McCord'},
                        {u'dateadded': u'1428713719',
                         u'farm': 8,
                         u'id': u'16896411327',
                         u'isfamily': 0,
                         u'isfriend': 0,
                         u'ispublic': 1,
                         u'owner': u'62532775@N03',
                         u'ownername': u'Jibup',
                         u'secret': u'76dc9110ed',
                         u'server': u'7695',
                         u'title': u'Caterpillar'},
                        {u'dateadded': u'1428554028',
                         u'farm': 8,
                         u'id': u'17058845816',
                         u'isfamily': 0,
                         u'isfriend': 0,
                         u'ispublic': 1,
                         u'owner': u'73369431@N07',
                         u'ownername': u'Stephen Ball Photography',
                         u'secret': u'607f522144',
                         u'server': u'7705',
                         u'title': u'One Up One Down'}],
             u'total': u'3097'},
 u'stat': u'ok'}

I have used a small page size of 3 for demo purposes - the default is 100 and the maximum is 500. This means that you will need to make multiple calls to the service to retrieve all of the photos. You could loop like this:

group_pool_photos = []
group_id = '544735@N20'    # caterpillarequipment's group_id
page = 1
success = True
while True:
    response = flickr.groups.pools.getPhotos(group_id=group_id, page=page)
    if response['stat'] != 'ok':
        print 'Error occurred in flickr.groups.pools.getPhotos'
        pprint(response)
        success = False
        break

    if len(response['photos']['photo']) == 0:
        break

    group_pool_photos.extend(response['photos']['photo'])
    page += 1

if success:
    print 'Info for all pool photos successfully retrieved. Total photos {}'.format(len(group_pool_photos))

At the end of this group_pool_photos should contain all photo info.

NB It's possible that the pool might change due to additions or deletions of photos during the retrieval process, so you might want to try and detect that by comparing the total in successive responses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM