How it works...

This recipe demonstrates how to interact with Flickr using its REST APIs. In this example, the collect_photo_info() tag takes three parameters: Flickr API key, a search tag, and the desired number of search results.

We construct the first URL to search for photos. Note that in this URL, the value of the method parameter is flickr.photos.search and the desired result format is JSON.

The results of the first GET() call are stored in the resp variable and then converted to the JSON format by calling the json() method on resp. Now, the JSON data is read in a loop looking into the ['photos']['photo'] iterator. A photo_collection list is created to return the result after organizing the information. In this list, each photo's information is represented by a dictionary. The keys of this dictionary are populated by extracting information from the earlier JSON response and another GET request to get the information regarding the specific photo.

Note that to get the comments about a photo, we need to make another GET() request and gather comment information from the ['comments']['comment'] elements of the returned JSON. Finally, these comments are appended to a list and attached to the photo dictionary entry.

In the main function, we extract the photo_collection dictionary and print some useful information about each photo.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.208.12