Displaying a sets images from Flickr with CFlickr

In the last part we looked at how to pull out a specific users sets from Flickr using the CFlickr API.

This episode looks at using that set id to display the images within.

First we start off with starting up the CFlickr Object and loading the PhotosetsInterface

<cfset flickr = createobject("component", <!--- change to use your API key --->
<cfset flickr.init("yourAPIkey")>
<!--- Get the interface we want to work with --->
<cfset setInterface = flickr.getPhotosetsInterface()>

Following on from my last post about displaying the sets, we are passing the set id in through the URL.s variable. So lets get the array of photos in the set, and some info on the set itself.

<cfset photoList = setInterface.getPhotos(photoset_id=#url.s#)>
<cfset arrayPhotos = photoList.getPhotos()>
<cfset setInfo = setInterface.getInfo(photoset_id=#url.s#)>

Display the title of the set to the user

<h1>#setInfo.getTitle()# (#setInfo.getTotal()#)</h1>

Lets loop over the array of photos, and save the title for future use.

<cfloop from="1" to="#arraylen(arrayPhotos)#" index="i">
   <cfset photo = arrayPhotos[i]>
   <cfset title = photo.getTitle()>
   ...
</cfloop>

I am using the small square photo, just as in the sets display, that Flickr produces for every photo, it just provides a nicer layout.

<img src="#photo.getPhotoUrl(photo.SIZE_SMALL_SQUARE)#" border="0" alt="#title#"/>

And wrapping a link around that

<a href="#photo.getPhotoUrl()#" title="#htmlEditFormat(title)#">....</a>

Completed code (c'mon that was pretty easy right?):

<cfset photoList = setInterface.getPhotos(photoset_id=#url.s#)>
<cfset arrayPhotos = photoList.getPhotos()>
<cfset setInfo = setInterface.getInfo(photoset_id=#url.s#)>
<cfoutput>
<h1>#setInfo.getTitle()# (#setInfo.getTotal()#)</h1>
<table id="photoTable">
   <tr>
   <cfloop from="1" to="#arraylen(arrayPhotos)#" index="i">
      <cfset photo = arrayPhotos[i]>
      <cfset title = photo.getTitle()>
      <td width="12%">
         <div class="menuBody" style="text-align:center;">
         <a href="#photo.getPhotoUrl()#" title="#htmlEditFormat(title)#">
            <img src="#photo.getPhotoUrl(photo.SIZE_SMALL_SQUARE)#" border="0" alt="#title#"/>
         </a>
         </div>
      </td><cfif i mod 7 eq 0></tr><tr></cfif>
   </cfloop>
   </tr>
</table>

Comments
amin's Gravatar I've been tested your examples here. That's fine. But could you show more,
how to show our photos only. I want to fetch the comments altogether and the
tags too. Could guide me?
# Posted By amin | 03/09/07 21:32
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001.