 |
 |
|
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.
|
|
|
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 |
|
|
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 |
|
|
| |
|
| |
| |
| |
|
| |
|
|
| |
|
|
|
 |
|