Sure, Flickr, has over 5 billion photos with all sorts of meta information (like location or subject of the photo) connected to them. Wouldn't it be nice to access those photo's and data within your own application? This is were connecting to the Flickr API comes in handy. So nice of the folks at Flickr to provide a REST Webservice for just doing that.

REST (Representational state transfer) is a way to create, read, update or delete information on a server using a HTTP request (a more complex alternative would be SOAP). The response from Flickr will be in XML (other REST response formats would be JSON, HTML or CSV). At Flickr there are currently about 180 HTTP callable methods. They are all listed under 'API Methods' at the far right of the Flickr API page.

  • Let's start with getting an API key, by clicking the 'Creat an App' link at the Flickr API page.
  • Check if your key is valid by calling the method flickr.test.echo with the URL The response should be:
  • The method to search for a photo on subject or tag is The URL for searching photos with the tag 'sunset' with a limit of 3 results would be The current (when you make your own request there will be a new result set due to added photographs with the tag 'sunset') response from Flickr:
  • Since the response is in XML we don't see the actual photo yet. However, if you look closely at the response there is a photo id and owner stated: for the first photo node id="14577962925" and owner="125902894@N06". With those values the photo URL at Flickr can be deducted since a photo URL consists of So, let's visit You should see the webpage with the picture now: flickr-rest-how-to-Sunset-1

  • In our application we want to show pictures i.e. photographs not webpages. If we examine the above webpage we see the actual image file is stored at (with a smaller version at and a bigger one at

  • If we examine the URL we recognize the farm attribute farm="6", server attribute server="5507", id attribute id="14577962925" and secret attribute secret="c6ed60db6a" we've seen earlier in the Flickr XML response.

  • How to transform the XML response from Flickr to actual images being displayed? Here's were the PHP function simplexml_load_file() comes to the rescue. This function interprets an XML file into an object which makes it ease to iterate over each photo node.

  • Let's write the class with the function simplexml_load_file() included:

  • The only thing left to do is to make the form to pass the requested data to the class:
  • Let's see the result of our work; try the form below!

  • My custom Flickr photo search app