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















7700791852

uhffxszhhghuteucglgk posted a photo:

7700791852

Photo by 44564547@N00


5283307083

uhffxszhhghuteucglgk posted a photo:

5283307083

Photo by 54238729@N07


8085985621

uhffxszhhghuteucglgk posted a photo:

8085985621

Photo by 36692668@N05


8046848941

uhffxszhhghuteucglgk posted a photo:

8046848941

Photo by 84311092@N06


Appointment ceremony of POCOG's consultant in the 19th World OKTA Leaders Convention

PyeongChang2018_kr posted a photo:

Appointment ceremony of POCOG's consultant in the 19th World OKTA Leaders Convention

20170427 제19차 세계대표자대회-자문위원 위촉식


Appointment ceremony of POCOG's consultant in the 19th World OKTA Leaders Convention

PyeongChang2018_kr posted a photo:

Appointment ceremony of POCOG's consultant in the 19th World OKTA Leaders Convention

20170427 제19차 세계대표자대회-자문위원 위촉식


Appointment ceremony of POCOG's consultant in the 19th World OKTA Leaders Convention

PyeongChang2018_kr posted a photo:

Appointment ceremony of POCOG's consultant in the 19th World OKTA Leaders Convention

20170427 제19차 세계대표자대회-자문위원 위촉식


Appointment ceremony of POCOG's consultant in the 19th World OKTA Leaders Convention

PyeongChang2018_kr posted a photo:

Appointment ceremony of POCOG's consultant in the 19th World OKTA Leaders Convention

20170427 제19차 세계대표자대회-자문위원 위촉식


Appointment ceremony of POCOG's consultant in the 19th World OKTA Leaders Convention

PyeongChang2018_kr posted a photo:

Appointment ceremony of POCOG's consultant in the 19th World OKTA Leaders Convention

20170427 제19차 세계대표자대회-자문위원 위촉식


2017 Area 18 Spring Games - ST-8798

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-8798

Photo by Sam Tang


2017 Area 18 Spring Games - ST-8790

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-8790

Photo by Sam Tang


2017 Area 18 Spring Games - ST-8774

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-8774

Photo by Sam Tang


2017 Area 18 Spring Games - ST-8751

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-8751

Photo by Sam Tang


2017 Area 18 Spring Games - ST-8796

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-8796

Photo by Sam Tang


2017 Area 18 Spring Games - ST-8803

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-8803

Photo by Sam Tang


2017 Area 18 Spring Games - ST-9037

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-9037

Photo by Sam Tang


2017 Area 18 Spring Games - ST-8784

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-8784

Photo by Sam Tang


2017 Area 18 Spring Games - ST-9023

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-9023

Photo by Sam Tang


2017 Area 18 Spring Games - ST-8809

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-8809

Photo by Sam Tang


2017 Area 18 Spring Games - ST-8776

Special Olympics ILL posted a photo:

2017 Area 18 Spring Games - ST-8776

Photo by Sam Tang