Mauro Pirrone | Blog

Design & Logic Arts

Integrating Flickr with your PHP website

Posted in Web Design, Web Development by Mauro on the May 31st, 2008

Flickr is an image and video hosting website. Luckily enough, they provide a web service to access your photos and use them in any way you want. To get you into perspective, here’s the Flickr photoset which I am using, and here are the customised photo gallaries which I created using PHP:

Although I’m showing you how to integrate Flickr with Lightbox and PostCardViewer, this technique works with any photo gallery including the commercial one SlideShowPro.

Step 1

Downlaod the phpFlicker library from http://phpflickr.com/

Download Lightbox or PostCardViewer (or any other photo gallery).

Step 2

To access Flickr using a web service, you need an API key. You may get one from http://www.flickr.com/services/api/keys

Step 3

Get the photoset ID. In this case I am using photoset id ‘72157605353756648′. Note that the photoset id is part of the URL. For example, http://www.flickr.com/photos/26262208@N07/sets/72157605353756648/

Step 3

Step up your php script.

require_once("phpFlickr/phpFlickr.php");
$f = new phpFlickr("your api key");
$photoset_id = '72157605353756648';
$photos = $f->photosets_getPhotos($photoset_id);

Step 4

Loop through each photo in the photoset and you’re done! The following example uses the Lightbox photo gallery.

<ul>
<?php foreach ($photos['photo'] as $photo): ?>
<li><a rel="lightbox[roadtrip]" href="<?= $f->buildPhotoURL($photo, ‘medium’) ?>" title="<?= $photo['title'] ?>"><img src="<?= $f->buildPhotoURL($photo, ’square’) ?>" alt="<?= $photo['title'] ?>" title="<?= $photo['title'] ?>" /></a></li>
<?php endforeach; ?>
</ul>

Notes

  • You may easily change the file size by specifying either square, thumbnail, small, medium, large or original. For example: $f->buildPhotoURL($photo, ‘large’)
  • You may programmatically get the photoset ids by using the API call photoset.getList (or photoset_getList method)
  • You may also use API calls to get comments, upload photos, and so on
  • For the complete API documentation visit here

Source Code Download

2 Responses to 'Integrating Flickr with your PHP website'

Subscribe to comments with RSS or TrackBack to 'Integrating Flickr with your PHP website'.

  1. luis garcia said,

    on June 29th, 2008 at 9:25 am

    I don’t get it work…… some one did?

  2. Mauro said,

    on June 29th, 2008 at 9:53 am

    You’re possibly doing something wrong. If you’ve downloaded the source code, all you have to do is, get an API key and set your Flickr photo set ID.

Leave a Reply

*
You need to verify your identity by entering the code shown below.
This helps preventing automated programs from using this form.

Anti-Spam Image