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















23062017-_MG_6378.jpg

tjmic_92 posted a photo:

23062017-_MG_6378.jpg


23062017-_MG_6382.jpg

tjmic_92 posted a photo:

23062017-_MG_6382.jpg


23062017-_MG_6380.jpg

tjmic_92 posted a photo:

23062017-_MG_6380.jpg


23062017-_MG_6381.jpg

tjmic_92 posted a photo:

23062017-_MG_6381.jpg


23062017-_MG_6374.jpg

tjmic_92 posted a photo:

23062017-_MG_6374.jpg


23062017-_MG_6377.jpg

tjmic_92 posted a photo:

23062017-_MG_6377.jpg


23062017-_MG_6376.jpg

tjmic_92 posted a photo:

23062017-_MG_6376.jpg


23062017-_MG_6379.jpg

tjmic_92 posted a photo:

23062017-_MG_6379.jpg


Korea Land And Geospatial Informatix Corporation (LX) Makes a Donation to POCOG

PyeongChang2018_kr posted a photo:

Korea Land And Geospatial Informatix Corporation (LX) Makes a Donation to POCOG

20170626 LX한국국토정보공사 기부금 전달식


Korea Land And Geospatial Informatix Corporation (LX) Makes a Donation to POCOG

PyeongChang2018_kr posted a photo:

Korea Land And Geospatial Informatix Corporation (LX) Makes a Donation to POCOG

20170626 LX한국국토정보공사 기부금 전달식


Gangneung Culture & Arts Foundation signs MOU with POCOG

PyeongChang2018_kr posted a photo:

Gangneung Culture & Arts Foundation signs MOU with POCOG

20170626 강릉문화재단 업무협약식


Korea Water Resources Corporation (K-water) signs MOU with POCOG

PyeongChang2018_kr posted a photo:

Korea Water Resources Corporation (K-water) signs MOU with POCOG

20170628 한국수자원공사 업무협약식


Gangneung Culture & Arts Foundation signs MOU with POCOG

PyeongChang2018_kr posted a photo:

Gangneung Culture & Arts Foundation signs MOU with POCOG

20170626 강릉문화재단 업무협약식


Golfer Bo-mee Lee Named the PyeongChang 2018 Honorary Ambassador

PyeongChang2018_kr posted a photo:

Golfer Bo-mee Lee Named the PyeongChang 2018 Honorary Ambassador

20170627 이보미 홍보대사 위촉식


Golfer Bo-mee Lee Named the PyeongChang 2018 Honorary Ambassador

PyeongChang2018_kr posted a photo:

Golfer Bo-mee Lee Named the PyeongChang 2018 Honorary Ambassador

20170627 이보미 홍보대사 위촉식


Golfer Bo-mee Lee Named the PyeongChang 2018 Honorary Ambassador

PyeongChang2018_kr posted a photo:

Golfer Bo-mee Lee Named the PyeongChang 2018 Honorary Ambassador

20170627 이보미 홍보대사 위촉식


Golfer Bo-mee Lee Named the PyeongChang 2018 Honorary Ambassador

PyeongChang2018_kr posted a photo:

Golfer Bo-mee Lee Named the PyeongChang 2018 Honorary Ambassador

20170627 이보미 홍보대사 위촉식


Vice Minister of Culture, Sports and Tourism visits POCOG

PyeongChang2018_kr posted a photo:

Vice Minister of Culture, Sports and Tourism visits POCOG

20170627 노태강 문체부2차관 방문


Vice Minister of Culture, Sports and Tourism visits POCOG

PyeongChang2018_kr posted a photo:

Vice Minister of Culture, Sports and Tourism visits POCOG

20170627 노태강 문체부2차관 방문


Vice Minister of Culture, Sports and Tourism visits POCOG

PyeongChang2018_kr posted a photo:

Vice Minister of Culture, Sports and Tourism visits POCOG

20170627 노태강 문체부2차관 방문