Hacking Flickr
Jason Famularo has made a nice Google module to display one or a set of Flickr pictures. The problem is that I want to display one of my own images in a random fashion. The Flickr API has a flickr.photos.search method that allows you to retrieve the photos of a specific user. The problem is that you cannot retrieve them in a random order. There are the only parameters that allow you to change the photo order:
min_upload_date
Photos with an upload date greater than or equal to this value will be returned. The date should be in the form of a unix timestamp.
max_upload_date
Photos with an upload date less than or equal to this value will be returned. The date should be in the form of a unix timestamp.
min_taken_date
Photos with an taken date greater than or equal to this value will be returned. The date should be in the form of a mysql datetime.
max_taken_date
Photos with an taken date less than or equal to this value will be returned. The date should be in the form of a mysql datetime.
sort
Deafults to date-posted-desc. The possible values are: date-posted-asc, date-posted-desc, date-taken-asc, date-taken-desc, interestingness-desc, interestingness-asc, and relevance.
This means that I had to find a “hack” ![]()
A first solution would be to retrive a block of say 50 pictures (or all the pictures!) and then parse the XML to take some random nodes.
A better solution would be to call flickr.people.getInfo the first time to retrieve the number of photos a specific user has published (call it UMAX). The you call flickr.photos.search for each photo setting the per_page parameter to 1 (only one photo at a time) and the page parameter to a random number in the range 1-UMAX.
It’s not very performant, I know, but it’s a nice and quick solution. Let’s just hope the flickr guys will add some parameter to their API!!