Knowpapa.com - a developer's blog

Parsing Flickr Feeds using PHP Simple XML API

With over 5 billion photos (many with valuable metadata such as tags, geolocation, and Exif data) and a large section of it with creative common license – the flickr feed can be a handy resource for developers to enhance usability of their web applications.

The first thing to do is to grab the flickr feed for images with creative common license. The feed for Flick is:

http://api.flickr.com/services/feeds/photos_public.gne

The flickr feed supports the following query parameters:

id (Optional)
A single user ID. This specifies a user to fetch for.
ids (Optional)
A comma delimited list of user IDs. This specifies a list of users to fetch for.
tags (Optional)
A comma delimited list of tags to filter the feed by.
tagmode (Optional)
Control whether items must have ALL the tags (tagmode=all), or ANY (tagmode=any) of the tags. Default is ALL.
format (Optional)
The format of the feed. See the feeds page for feed format information. Default is Atom 1.0.
lang (Optional)
The display language for the feed. See the feeds page for feed language information. Default is US English (en-us).

Now assuming that a page in our web-application relates to latest news from the London Olympics. So we can look for the latest photographs in the feed using the tag olympics. Our new feed URL then becomes:

http://api.flickr.com/services/feeds/photos_public.gne?tags=olympics

Now all we need is to parse the feed content. PHP5 comes with a powerful bundled extension API called simpleXML which allows for parsing contents the pure OOP way.

echo "Latest Images from London Olympics";
$feed = file_get_contents 
("http://api.flickr.com/services/feeds/photos_public.gne?tags=olympics");
$xmlparse = simplexml_load_string ($feed);
// now time to display the images
foreach ($xmlparse as $item)
{
echo "link['href']}'>".$item->title."
";
echo $item->content."
"; // this line takes care of the attribution requirement for the photos.
}

That is it – and the output would look something like this (you can use css to stylise it ):

Latest Images from London Olympics















IMG_0393

MiserableAZever posted a photo:

IMG_0393

OLYMPIC LEGACY SKI JUMPS, CALLAGHAN VALLEY


Running Exercise Workout - Credit to informedmag.com

Informedmag posted a photo:

Running Exercise Workout - Credit to informedmag.com

Must Credit to: 'http://informedmag.com/' not Flickr.
Copy Link Address: informedmag.com/


Running Mountains Nature - Credit to informedmag.com

Informedmag posted a photo:

Running Mountains Nature - Credit to informedmag.com

Must Credit to: 'http://informedmag.com/' not Flickr.
Copy Link Address: informedmag.com/


Running Olympics Nike - Credit to informedmag.com

Informedmag posted a photo:

Running Olympics Nike - Credit to informedmag.com

Must Credit to: 'http://informedmag.com/' not Flickr.
Copy Link Address: informedmag.com/


Running Marathon Woods Competition - Credit to informedmag.com

Informedmag posted a photo:

Running Marathon Woods Competition - Credit to informedmag.com

Must Credit to: 'http://informedmag.com/' not Flickr.
Copy Link Address: informedmag.com/


Running Marathon Competition Exercise - Credit to informedmag.com

Informedmag posted a photo:

Running Marathon Competition Exercise - Credit to informedmag.com

Must Credit to: 'http://informedmag.com/' not Flickr.
Copy Link Address: informedmag.com/


Panathenaic Stadium

pulpedpastel posted a photo:

Panathenaic Stadium

aka Kallimarmaro, which literally translates to "beautiful marble", because this is what it's entirely made of. This is also the home of the first modern Olympics in 1896.


EDGEWATER - Seattle, WA

matthewkaz posted a photo:

EDGEWATER - Seattle, WA

_MG_0453.jpg


Nagano Winter Olympics

Bakuman3188 posted a photo:

Nagano Winter Olympics


17 02 16_0664 edit

bradfordst219 posted a photo:

17 02 16_0664 edit


17 02 16_0669 edit

bradfordst219 posted a photo:

17 02 16_0669 edit


17 02 16_0659 Edit 8x10

bradfordst219 posted a photo:

17 02 16_0659 Edit  8x10


17 02 16_0681 edit good

bradfordst219 posted a photo:

17 02 16_0681 edit good


17 02 16_0702 edit

bradfordst219 posted a photo:

17 02 16_0702 edit


17 02 16_0703 edit nice

bradfordst219 posted a photo:

17 02 16_0703 edit nice


17 02 16_0697 edit SOCHI CC

bradfordst219 posted a photo:

17 02 16_0697 edit  SOCHI CC


17 02 16_0657 edit

bradfordst219 posted a photo:

17 02 16_0657 edit


Stars & Man

rstephen2 posted a photo:

Stars & Man


EACH OF US WHO PURSUES THAT WHICH IS OFTEN ELUSIVE POSSESSES, I BELIEVE, THREE QUALITIES. MEANING, PURPOSE, AND DREAMING. WITHOUT THE FIRST TWO THE THIRD WOULD NEVER EXIST.


March through the Past

David Applebury posted a photo:

March through the Past


Never Stop

rstephen2 posted a photo:

Never Stop

I FOUND THE SINGLE BIGGEST THING THAT HOLDS US BACK IS OURSELVES. GETTING KNOCKED DOWN TIME AND TIME AGAIN IS PART OF WINNING, IT'S THE GETTING UP OFF THE FLOOR EVERYTIME THAT MAKES YOU A WINNER.