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:
phpFlickr. Accomplishing the same task in each
kit will enable you to contrast and compare them.
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.
Some of the XML parsing can be made much simpler if you have
access to PHP 5 and the
extensions, but since many folks are forced to live with PHP 4,
we'll keep these programs compatible with the earlier
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).
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 ...