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 #39. Talk to the API with PHP

PHP is a good choice for creating web-based Flickr tools.

Having looked at how to talk to the API in Perl [Hack #38] , this hack accomplishes the same tasks in PHP. Again, we'll start with a simple example and then move on to a more complicated task using the two available API kits: PEAR::Flickr_API and phpFlickr. Accomplishing the same task in each kit will enable you to contrast and compare them.

What You Need

Since we're programming in PHP, you'll need a web server with PHP installed. All the programs in this hack require PHP 4 or later.

Tip

Some of the XML parsing can be made much simpler if you have access to PHP 5 and the SimpleXML extensions, but since many folks are forced to live with PHP 4, we'll keep these programs compatible with the earlier version.

We'll be using the two currently available API kits for talking to Flickr from PHP: PEAR::Flickr_API (available at http://code.iamcal.com/php/flickr/) and phpFlickr (available at http://www.phpflickr.com).

Tip

Any new API kits that become available after the publication of this book will be listed at the Flickr API page (http://www.flickr.com/services/api/).

Talking to the Flickr API in any language requires that you solve two fundamental problems. The first problem is how to issue a call to the API. The second is how to parse the XML you get back. In PHP 4, solving the first problem is quite simple, but picking your way through the tangly XML thicket can be a challenge.

We'll start with a program ...

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