Accessing Flickr with ColdFusion

I love it each and every time I see a company offer an API for their product/service. The list is growing quite long these days, including Amazon, eBay, of course the Macromedia News Aggregator itself, and my personal favorite, Flickr. The Flickr API is really very extensive, allowing access to just about every feature they have to offer. When I ran down the list of “API Kits” I noticed that ColdFusion was not represented among the list of examples. With this in mind, I set out to see exactly what it would take.

The result is that it’s excessively simple to access and work with the Flickr API through ColdFusion.

I chose the REST option for my example. For this type of access there are two distinct parts. The first is an HTTP request to the Flickr services. The URL of the HTTP request is expected to have various query string parameters depending on what method you want to access and that method’s parameters. The second part is a response to the HTTP request, but rather than getting HTML in return, a REST service gets XML formatted data.

As a simple example, when accessing the “flickr.test.echo” method, the HTTP request URL might be:

http://www.flickr.com/services/rest/?method=flickr.test.echo&api_key=123&foo=bar

This is a test method provided by the nice folks at Flickr as a means to … uh .. test your request and make sure things are working the way you expect. As previously discussed, the response is XML formatted data. In this case, the echo method responds by simply echoing the parameters you passed in the request. Formatted as XML the above request might get a response that looks something like the following:

<rsp stat=”ok”>
  <method>flickr.test.echo</method>
  <api_key>123</api_key>
  <foo>bar</foo>
</rsp>

What does this mean from a ColdFusion perspective? Well, let’s break it down. We need to make an HTTP request and pass query string parameters. Okay, that’d be CFHTTP and CFHTTPPARAM. We get back an XML formatted data that we’ll likely want to work with to determine what to display. Okay, that’s the XmlParse() function provided by CFML. We might also want to display something specific from those results, which would require CFOUTPUT. Seems pretty basic, right? It is!

Here’s a complete example (minus my personal API key of course) that uses the echo method of the Flickr API, and in this case simply iterates through the return parameters in an HTML page.

<cfparam name=”flickr” default=”http://www.flickr.com/services/rest/” />
<cfparam name=”key” default=”123″ />

<cfhttp url=”#flickr#”>
  <cfhttpparam name=”api_key” type=”url” value=”#key#” />
  <cfhttpparam name=”method” type=”url” value=”flickr.test.echo” />
  <cfhttpparam name=”message” type=”url” value=”ColdFusion” />
</cfhttp>

<cfset doc = XmlParse( CFHTTP.FileContent ) />

<html>

  <head>
    <title>Flickr Echo with ColdFusion</title>
  </head>

  <body>

    <cfloop index=”sub” from=”1″ to=”#ArrayLen( doc.rsp.XmlChildren )#” step=”1″>
      <cfoutput>#doc.rsp.XmlChildren[sub]#</cfoutput> <br />
    </cfloop>

    <!— If you’d like to see the XML document… —>
    <!— <cfdump var=”#doc#” /> —>

  </body>

</html>

This is clearly far from a complete API kit for ColdFusion but, in many cases, it’s so simple to access Flickr with ColdFusion that it almost doesn’t even really need one.

9 Responses to “Accessing Flickr with ColdFusion”

  1. Jeff Says:

    There is a really cool example of using Flickr on Flex Authority. Manish Jethani created a graphical version of del.icio.us, utilizing images read from the Flickr API.

    Try it here: http://www.flexauthority.com/samplesIndex.cfm?sampleID=13

  2. Kevin Hpyt Says:

    Hey Jeff,

    I had started on a Flex version of the Flickr viewer complete with note functionality. I was making it to show how to access Flickr with Flex. Looks like Manish has taken care of that for me now. Thanks for the reference!

    Regards,
    Kevin

  3. Anonymous Says:

    girls pissing

    hidden bathroom cameras public pissing pissing girls men pissing girls pissing pissing girls pissing girls 1 Room DIRECTV HD FREE > 2 Room DIRECTV…

  4. Free Directv Direct Says:

    I agree with you.

  5. Direct Directv Direct Says:

    Me too.

  6. penis extenders Says:

    I agree with you the way you view the issue. I remember Jack London once said everything positive has a negative side; everything negative has positive side. It is also interesting to see different viewpoints & learn useful things in the discussion.

  7. Agnieszka Says:

    Wow. cool site.

  8. Telewizory lcd Says:

    I also oneself something would want to find out on this theme. Very attentively I will read every post.

  9. Chris Blackwell Says:

    Accessing Flickr from CF is very is, but an API can always make things easier.

    http://chris.m0nk3y.net/projects/CFlickr/

Leave a Reply