Flickr API Wrapper
July 27, 2009 | Posted in Freebies, PHPThere are already a couple PHP Flickr API classes out there, but they all seemed a bit over-complicated. Flickr has already done all the work for us, so why make it harder than it is. They've even got all the documentation, so if you ever need to know anything about it, just head over there.
This class makes making a request to Flickr's API very simple. And it returns the results as a PHP object. It will even cache your requests so you aren't hitting Flickr as often, thus increasing the speed and performance of this script.
<?php
$api_key = 'your_flickr_api_key_here';
$flickr = new Flickr($api_key);
$params = array
(
'user_id' => 'your_flickr_user_nsid_here',
'extras' => 'url_m,url_sq',
'per_page' => 10,
);
$result = $flickr->call('people.getPublicPhotos', $params);
foreach ($result->photos->photo as $photo)
{
$p = $flickr->call('photos.getInfo', array('photo_id' => $photo->id));
echo '<h2>'.$photo->title.'</h2>';
echo '<a href="'.$photo->url_m.'"><img src="'.$photo->url_sq.'" alt="" /></a>';
echo nl2br($p->photo->description->_content);
}
// Example using chaining
$result = Flickr::factory($api_key)->call('people.getPublicPhotos', $params);
For a live demo, just check out my sidebar over on the right.
So I've been noticing quite a few articles lately about speeding up your website, and compressing static files and all that. It got me thinking, and I started to mess around with some ideas I had.










