I wish to list all the sets created by this user along with the set id. I am using flickrApi and Python. Here’s my code. The setName is returning “none” in the output.
The elm.get(‘title’) is returning “none”.
import flickrapi
api_key = 'APIKEY'
api_secret = 'APISECRET'
flickr = flickrapi.FlickrAPI(api_key, api_secret)
(token, frob) = flickr.get_token_part_one(perms='write')
if not token: raw_input("Press ENTER after you authorized this program")
flickr.get_token_part_two((token, frob))
try:
favs = flickr.photosets_getList(user_id='51784048@N00')
#favs = flickr.favorites_getPublicList(user_id = '51784048@N00')
for elm in favs.getiterator():
print ("id: %s secret: %s setname: %s") %(elm.get('id'), elm.get('secret'), elm.get('title'))
except:
raise Exception("Some error encountered!")
When you’re working with
flickrapiin Python, it’s frequently useful to print the XML which is returned by the API calls in order to see what’s going on. In your example, if you add:… at the top, and then add:
… you’ll see that the structure returned is:
In a real application, you’d want to check the return status and check the
pageattributes, but to quickly get to what you want, let’s just look at the<photoset>elements. To iterate over them, you can change your loop to:Then you’ll see the structure of each
photosetelement that you’ll have to navigate. For example, one would be:… so the title is actually stored in a
titlesub-element. From that, you can see that to get the information that you want, you can do:… which produces the output:
etc.