Just One Show

Make the Flickr PHP API not so ugly and easier to use
2 comments      Added on 01/29/08 by Kris
For months I have been bypassing the Flickr API and using RSS 2.0 feeds instead. The reason? They come with all the photo stream data that you need in a nice little package. Things like title, description, tags, date taken, date uploaded, image dimensions, etc.

What is missing from the RSS feed the ability to load comments with a photo and choose how many items are returned in the feed. The API, however, will let you load hundreds of images and load comments for each photo.

There is a catch though. The API is broken up into about a 75 different calls. Not one single call to the server can match the data that is returned in the RSS feed. To get the same data I need to make approximately 8 different calls to Flickr. Not good.

What use is the API?

It gives me the ability to create a historical back up of my photos in their most basic form with urls, date, descriptions (with html stripped) and tags. It also gives someone building an application a rich data source to do some of the things that Flickr isn't already doing - the purpose of an API.

After working with it for a few hours I became frustrated. PHP is my poison of choice and the PHP examples that Flickr uses all return serialized data. Which is great and easy to work with if you already know what the XML namespaces are but without them it is hard to access the data. And in some cases impossible without printing out the serialized array and looking at it because the returned serialized array's keys don't match the XML namespaces. Not to mention children are buried in deeper arrays that aren't as easy to access as say $title = $item->photo['title'].

Here's how I cleaned up the mess. If you are PHP guru then I am sure you could get this down to one script.

An 'include' script, sort of. View this script by URL on your server to see all name spaces:

1) Create a new PHP file declaring xml as file type - header("Content-Type: text/xml")
2) Use the url that Flickr supplies to return content in REST format
3) Comment out the line for serialization
4) Use PHP's file_get_contents() function
5) echo the returned XML



A loader script:

1) Create a loader script
2) Call the include script - $resp = simplexml_load_file("YOUR INCLUDE SCRIPT URL");
3) Get the data out by name space, the same ones that Flickr documents



To view the name spaces that you will want to access simply open up the include script by url in your browser.

For now I will stick with the RSS 2.0 feeds for blog submissions but once I have some free time I will be using the API code above to create a cached archive for my own safe keeping.
  

Tags
  photo frame  digital  Flickr API  PHP  simple  simplexml_load_file  



16m PHOTO FRAME 1.5" DIGITAL PIC KEYCHAIN FREE S/H
Current bid: $6.51 on eBay
7" Widescreen LCD Digital Photo Frame+Video MP3 Player
Current bid: $57.99 on eBay
See all 10,642 photo frame items on eBay.  



2 Comments
1

Here is what I do to get into a nice array:

/* FLICKR Integration */
$flickr_params = array(
'api_key' => 'key',
'method' => 'flickr.people.getPublicPhotos',
'user_id' => 'userid',
'per_page' => 3,
'format' => 'php_serial'
);

foreach ($flickr_params as $k => $v){
$encoded_params[] = urlencode($k).'='.urlencode($v);
}
#
# call the API and decode the response
#
$flickr_url = "http://api.flickr.com/services/rest/?".implode('&', $encoded_params);
$flickr_get_content = file_get_contents($flickr_url);
$flickr = unserialize($flickr_get_content);

Then you can look at what you get with print_r() or var_dump() and go from there.

 
Posted by: Stepan  at: 10:19am 01/29/2008  
2

I'm with you 100% that the code you are using works. It's the example that Flickr uses, and where I started this experiment this morning.

If you look at the array key that is returned for the 'secret' of a photo when it is serialized you won't find it. It gets returned as 'originalsecret'. That doesn't appear anyplace in the Flickr documentation.

This is a small stumbling block if you need to get the description or comments of a photo.

The larger problem for me occurs when I need to make new calls to the descriptions and comments of a photo. They are each separate calls and can only be done per photo. The array to get descriptions is multidimesional and again changes some of the keys to not match the documented namespaces or children (which are also in their own arrays).

This solution is easier for me to be able to see the namespaces outright and build them into the script. Also, for me, it makes trouble shooting much easier.

 
Posted by: Kris  at: 10:34am 01/29/2008  

 
Leave a comment
Name:
Email:
Url:
Comment:
 
 
 
 
<< view all shows
 
 



Have us over



Scrilla   Archive



7" LCD DIGITAL PHOTO FRAME PICTURE ALBUM
Current bid: $51.00 on eBay


New 1.5" LCD Digital Photo Frame Key Chain Silver
Current bid: $8.81 on eBay


New 15" Digital Photo Frame W/ Mp3,Alarm Clock,Calender
Current bid: $185.00 on eBay


NEW Barney Doll Photo Frame 5"x3.5" by Fisher-Price Toy
Current bid: $7.99 on eBay


7" Widescreen LCD Digital Photo Frame+Video MP3 Player
Current bid: $57.99 on eBay

See all 10,642 photo frame items on eBay.  
  June 2008 (7)
May 2008 (8)
April 2008 (11)
March 2008 (8)
February 2008 (10)
January 2008 (10)
December 2007 (6)
November 2007 (13)
October 2007 (12)
Sep. 2007 (11)
August 2007 (13)
July 2007 (11)
June 2007 (11)
May 2007 (13)
April 2007 (13)
February 2007 (10)
January 2007 (11)
December 2006 (13)
November 2006 (16)
October 2006 (12)
Sep. 2006 (10)
August 2006 (13)
July 2006 (14)
June 2006 (10)
May 2006 (12)
April 2006 (15)
March 2006 (9)
January 2006 (3)
December 2005 (4)
November 2005 (7)
October 2005 (13)
Sep. 2005 (13)
August 2005 (14)
July 2005 (7)
June 2005 (13)
May 2005 (13)
April 2005 (14)
March 2005 (13)
February 2005 (19)
January 2005 (21)
December 2004 (24)
November 2004 (18)