• Client login
  • Work for us

All the latest from the team...

Monday, 23 February 2009

Connecting with the Flickr API through PHP

Here at Code Required we've been playing with a lot of the Social networking apps over the months... Years and have started to think about the potential of putting them all together and seeing what comes out the other end...

We'll be posting samples of what you can do here and would love you guys to post your samples too!

Anyway to kick off here's how to get a list of your photos from Flickr using the phpFlickr class:

$f = new phpFlickr("YOUR_API_KEY");
$i = 0;

// Find the NSID of the username inputted via the form
$person = $f->people_findByUsername('YOUR_USER_NAME');

// Get the friendly URL of the user's photos
$photos_url = $f->urls_getUserPhotos($person['id']);

// Get the user's first 36 public photos
$photos = $f->people_getPublicPhotos($person['id'], NULL, 1, 8);

// Loop through the photos and output the html
foreach ((array)$photos['photos']['photo'] as $photo) {
echo "
<a href='".$f->buildPhotoURL($photo)."'>";
echo "<img width='43' style='margin:4px' border='0' alt='$photo[title]' ". //
>
"src='" . $f->buildPhotoURL($photo, "Square") . "' />";
echo "</a
>";
$i++;
// If it reaches the sixth photo, insert a line break
if ($i % 4 == 0) {
echo "
";
}
}


You can get your Flickr API key here and explore more cool stuff in the Flickr API Docs

Have fun!

Labels: , , , ,

RSS feed ATOM feed Add to Technorati Favorites View Jon Harvey's profile on LinkedIn