BlogCFC Flickr Images Pod

I have all of my photos over on Flickr and wanted a small blogCFC pod on the right side to display the most recent uploads. Here is how I did it.

First create a new pod within blogcfc, this is easily done by going to the /tags/layout.cfm and adding a line in amongst the other pods:

<cfinclude template="../includes/pods/images.cfm">

Now go to the /includes/pods directory and create an images.cfm file.

At this point I should mention that I have used CFlickr a full features CF implementation of the Flickr API. There are other ways of doing this in CF but I intend to do more with Flickr on my site soon. So if you want to use it, go download it! Your images.cfm should start out like any other pod, note the cachename attribute and title attribute in the cfmodule calls. Its important to rename these so that the pod doesnt overwrite another in the caching, and so you have a nice title.

<cfsetting enablecfoutputonly=true>
<cfprocessingdirective pageencoding="utf-8">

<cfmodule template="../../tags/scopecache.cfm" cachename="pod_images" scope="application" timeout="#application.timeout#">

<cfmodule template="../../tags/podlayout.cfm" title="Recent Flickr">
   <cfoutput>
   
   </cfoutput>

</cfmodule>

</cfmodule>

<cfsetting enablecfoutputonly=false>

Next put in the code for CFlickr. In this case we want all the images for my username Length. (For the purposes of this demo I have removed my API key get yours at Flickr API)

First in the top of the images.cfm add in the creation of the instance and hit the required method to fetch a users images.

<!-- Create an instance of the Flickr class--->
<cfset flickr = createobject("component", "CFlickr.Flickr")>
<!--- change to use your API key --->
<cfset flickr.init("123456789123456789")>

<!--- 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()>

<!--- Get the 4 most recent photos --->
<cfset photoList = usrInterface.getPublicPhotos(user_id=nsid,per_page=4,page=1)>
<cfset arrayPhotos = photoList.getPhotos()>

Now loop over the result and display them neatly with title and alt attributes filled with the title of the photo.

<div style="text-align:center;">
   <!--- Loop over the photos and output a thumbnail of each --->
   <cfloop from="1" to="#arraylen(arrayPhotos)#" index="i">
    <cfset photo = arrayPhotos[i]>

    <a href="http://www.flickr.com/photos/length" title="#photo.getTitle()#"><img src="#photo.getPhotoUrl(photo.SIZE_SMALL_SQUARE)#" border="0" alt="#photo.getTitle()#"/></a>
   </cfloop>
   <a href="http://www.flickr.com/photos/length">More from Length @ Flickr</a>
   </div>

And the end result is what you see on the right. The complete code is attached to this entry.

Comments
amin's Gravatar Is there anyway that we have an interface so that user can add us as a friend
and we just want people to input their email address or flickr username. And all of this is implemented in our site
# Posted By amin | 05/09/07 11:18
amin's Gravatar this code will produce only the public set. How do I retrieve photo for private set
# Posted By amin | 05/09/07 11:31
Edward Beckett's Gravatar Thanks for the cool examples ... I had a problem with the component though ... first, I had initialized the CFC with the same code that you show ... the result was that I had the same images from your blog on mine ... even though I had changed the loop to my flick url ... I could not figure out how to clear the cache ... then, I kept getting errors thrown from line 159 in the Flickr.cfc stating that lastrequest was not of type Flickr.cfc ... I could not figure out how to fix the problems ... so I just disabled the pod for now ... do you know how I can get it working correctly?
# Posted By Edward Beckett | 02/03/08 20:55
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001.