2010-12-24
Flickr API Corners: ID to URL
If you have the URL of a Flickr photo, and want the URL of the page containing that photo, here are two ways, one on the website, and one using the API.
(Why would you want to do this? Well, people seem to be good at breaking the terms of service and not linking back to Flickr with a photo. Perhaps it’s been through ffffound or tumblr, or it’s been used on a blog. If that happens, but you want to find out who posted it, carry on.)
Firstly, using the website. Say your URL is http://farm5.static.flickr.com/4031/4497550401_11d8d708a7_z.jpg. Select up to the number behind the final slash and replace the text with http://flickr.com/photo.gne?id=. You’ll be redirected to a page containing the photo. (It’s possible that the photo will be private, but you’ll still be told who the uploader was.) Note you don’t need to trim things from the end of the URL; Flickr’s smart enough to do that for you.
Secondly, through the API. Open up the API explorer and look at flickr.photos.getInfo. Again, look after the last slash, and copy the number there (in this case, 4497550401) into the “ID” field. Once you call the method, you’ll see a variety of information about the photo, including (at the bottom of the XML) a URL.
It’s possible, if you don’t sign the call, or if the photo’s private, that you’ll need the second (hex) string, in this case 11d8d708a7, in the “secret” field. Providing this grants a little more access to a photo than the ID alone, but you may still find that the photo is private.
There you have it: two ways to get from a Flickr photo ID to the URL of the page containing it.