Using the Flickr API to retrieve a list of photosets
[Edit: 7 years later, flickr’s changed their API to SSL only, so you may have to change all http references to https]
[Edit: 9 years later, here’s some simpler code: https://gist.github.com/neokoenig/d98f678054df0f08df77cba98ed30876 ]
Lots of good work has been done on the Flickr API with ColdFusion already: specifically, CFlickr – see http://chris.m0nk3y.net/projects/CFlickr/.
However, for my uses, I didn’t need anything near as complicated: All I wanted to do was to pull a list of photosets, their titles, primary thumbnail and description.
Thankfully, this is quite easy due to the Flickr API.
Part One: Making the request to Flickr
I’m assuming you have an API code, and know your userID:
<!---Flickr Params--> <!---url.reinit used to manually refresh--> <!--- Do we have this value? --> <!---Send my Request to Flickr: this will get an XML doc with all my public photosets--> <!---parse the XML doc--> <!---Is XML request returned properly?--> Failed <!---Set the time this was done--> <!---Parse/narrow down the info I need into an Array-->
Part Two: Output: I’ve got my XML data, and now just need to loop over the Array.
</pre> <h2>Photos</h2> <pre> <!--XML last cached #application.FlickrXmlstarted#--></pre> <div id="photoset" class="clear"> <!---Output primary image--> <img class="left" src="http://farm#photosets[i].XmlAttributes['farm']#.static.flickr.com/#photosets[i].XmlAttributes['server']#/#photosets[i].XmlAttributes['primary']#_#photosets[i].XmlAttributes['secret']#_s.jpg" /> <!---output title--> <h4><a href="http://www.flickr.com/photos/#userid#/sets/#photosets[i].XmlAttributes['id']#/">#photosets[i].title.xmltext#</a></h4> <!---If description exists, show--> #photosets[i].description.xmltext#</div> <pre>
And that’s it: I’ve cached the XML data in the Application scope for speed, and I’m looping over the XML data object. If a description exists for the set, it’s output.