Archive for the 'Web Services' Category

November 14th 2006

Fun With Flickr Feeds

Flickr has some really great web services, one of the easiest to use is the feeds service. To grab a set of data from flickr in XML format, just open the following URL in your application:
http://api.flickr.com/services/feeds/photos_public.gne?tags=[comma separated tags here]

by default, the feeds are returned in “plain” XML format, to make things more interesting you can specify a format parameter

prefer PHP data? just:

<?php
  include_once("http://api.flickr.com/services/feeds/\
                    photos_public.gne?tags={$tags}&format=php");
  // broken up to fit format, but in practice leave this as one line
  // i now have a $feed array set with all the feed data:
  print_r($feed);
?>

or perhaps json:
to use the json (in javascript) you must first define a function called jsonFlickrFeed which takes in one object. This object will be your flickr feed data, then below that in your HTML head, you include the feed url as a javascript src file:

  <head>
    <title>Flickr Testbed</title>
    <script type="text/javascript">
      var photos = null;
      function jsonFlickrFeed(feedData){
        photos = feedData;
      }
    </script>
    <script type="text/javascript" src="http://api.flickr.com/services/feeds/\
            photos_public.gne?tags=toothbrush,red&format=json">
    </script>
  </head>
...

to view all the other feed formats, check out the formats section of the Flickr Feeds page.

No Comments yet »