O'Reilly logo

Flickr Hacks by Jim Bumgardner, Paul Bausch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #41. Authenticate Users

phpFlickr takes most of the grunt work out of authentication.

Authenticating people is one of the more hassle-prone features of the API. This is why it's a good idea to use an API wrapper: it handles the nitty-gritty details.

For PHP programmers, Dan Coulter's phpFlickr does this job admirably well. I've found it to be the most well supported of the PHP wrappers currently available for Flickr. It even has its own web site, with documentation and example code, located at http://www.phpFlickr.com.

This hack creates a web application that displays a few of a user's most recent photos. We'll use authentication so that we can display the user's Private photos as well as Public photos.

What You Need

These scripts were written for PHP 4, so you'll need a web server with PHP 4 support.

You'll also need the phpFlickr package of API wrappers, which is available from http://www.phpFlickr.com. The package includes the following:

phpFlickr.php

This is the main source code file for phpFlickr. The remaining files are support files that are referenced from within phpFlickr.php.

auth.php

This is a sample callback script for authentication that Dan provides. We'll be making some modifications to it.

xml.php

This source file, written by Aaron Colflesh, provides an XML parser that is used by phpFlickr.

PEAR/

This directory contains source code for PEAR database access, which is used to implement phpFlickr's optional caching feature. I highly recommend that you install this code and use ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required