To Flickr or not to Flickr

Friday, November 30, 2007

I finally got my Flickr account working with sewcrates.com. I created a couple of sample photosets, and went about displaying them on a test page. It worked, but I’m disappointed. The Flickr terms of use limit the photos displayed on a page to 30, and a link back to the Flickr page from each photograph. There is also a rather significant delay as the API calls work through the Yahoo! systems. The photo download speeds once you have the list were quite good. It would be trivial to cache the results on a static page to avoid the delay. This doesn’t get around the terms of use limitations, however.

While coding, I ran into one snag: the Flickr API documentation uses PHP’s file_get_contents() to read the Flickr serialized output. Dreamhost does not permit the file_get_contents() call for URLs (the flag is allow_url_fopen in the PHP.ini file). Dreamhost’s wiki provides a very easy workaround using cURL.

The PHP serialized Flickr call function is as follows:

$v) $encoded_params[] = urlencode($k).'='.urlencode($v); $url="http://api.flickr.com/services/rest/?".implode('&', $encoded_params); $ch = curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5); $rsp=curl_exec($ch); curl_close($ch); $rsp_obj=unserialize($rsp); if ($rsp_obj['stat']!='ok') { echo 'Flickr call failed:
'; print_r($params); echo '
'; print_r($rsp_obj); return false; } else return $rsp_obj; } ?>

I created the following code to test the Flickr calls:

'flickr.photosets.getList'); $sets=flickr($params,true); $count=0; $sets=$sets['photosets']['photoset']; foreach($sets as $set) { $id=$set['id']; $title=implode(' ',$set['title']); $description=implode(' ',$set['description']); $count=$set['photos']; $params=array('method'=>'flickr.photosets.getPhotos','extras'=>'date_taken','photoset_id'=>$id); $photos=flickr($params,false); $photos=$photos['photoset']['photo']; foreach ($photos as $photo) { $params=array('method'=>'flickr.photos.getSizes','photo_id'=>$photo['id']); $sizes=flickr($params,false); echo ''; } } } ?>

While it was a fun exercise, I decided not to use Flickr to host my photos. There are too many limitations on how I can use the APIs. That means more coding for me, as I figure out a good way to store the photographs in my database. It’s also provides more flexibility in tagging and displaying the content. This means back to the drawing board on my database design.

 Seattle, WA | , ,