Listing sets from Flickr with CFlickr
CFlickr has some pretty cool stuff, the guy that developed it (Chris) has constructed the entire Flickr API in ColdFusion from what I can tell.
Today we are going to look at how to list a users sets via CFlickr. First you need to get the NSID for the user you want the sets for.
<cfset flickr = createobject("component", "CFlickr.Flickr")>
<!--- change to use your API key --->
<cfset flickr.init("yourAPIkey")>
<!--- Get the interface we want to work with --->
<cfset usrInterface = flickr.getPeopleInterface()>
<!--- Find the nsid for the user length --->
<cfset nsid = usrInterface.findByUsername("length").getID()>
First lets set up the PhotosetsInterface for the specificUser, in this case 'length', and retrieve the list of sets available.
<cfset setList = setInterface.getList(user_id=nsid)>
Next we will loop over the sets and display the name, and title image for that set.
Lets loop over the array first and set the title and id to variables so we dont have to call those methods twice in the loop.
<cfset title = setList[i].getTitle()>
<cfset id = setList[i].getId()>
.....
</cfloop>
Now lets pump out the image for this set, this code pulls out the photoURL for the primary photo in the set, and specifies that we want the nice 'size_small_square' small square version of that photo.
Lastly lets wrap that in a a tag so we can later get the photos in this set, put the title underneath and the number of photos in the set.
<br>#title# (#setList[i].getPhotoCount()#)</a>
And here is the complete finished product:
<cfoutput>
<h1>Photo Sets</h1>
<div class="body"><p>There are currently #arraylen(setList)# sets.</p></div>
<table id="photoTable">
<tr>
<cfloop from="1" to="#arraylen(setList)#" index="i">
<cfset title = setList[i].getTitle()>
<cfset id = setList[i].getId()>
<td width="25%" onClick="location.href='?s=#id#';">
<div class="menuBody" style="text-align:center;">
<a href="?s=#id#"><img src="#setList[i].getPrimaryPhoto().getPhotoURL(setList[i].getPrimaryPhoto().size_small_square)#" border="0" alt="#title#">
<br>#title# (#setList[i].getPhotoCount()#)</a>
</div>
</td>
<cfif i mod 4 eq 0></tr><tr></cfif>
</cfloop>
</tr>
</table>
</cfoutput>
Whilst working out how this all works cfdump is very much your friend. Remember that cfdump of an object will show you all the methods available in that class, and you can be invaluable in helping you work out where you go next.
The CFlickr CFC documentation is a great place to get started too.
In the next part, how to display images from a set.


Chris