Phlickr
Unit Tests
Phlickr ships with a set of unit tests to verify its functionality. The unit tests are divided into two separate suites, offline and online. The unit tests are written using PHPUnit2.
On UNIX systems you'll need to be case sensitive, on Windows everything gets forced to lowercase.
Contribue to Phlickr
Phlickr is released under the LGPL license. Contributions, corrections, and suggestions are always welcome.
Notes for developers:
- This project follows the PEAR coding standards.
- All the unit tests are written using PHPUnit2.
- Phlickr’s API documentation is extracted using PhpDocumentor.
Contributors
Thanks to all of the following people who helped improve Phlickr:
Code
- Kevin Davis
Ideas and feedback
- Rob Kunkle
- François Proulx
Tools built with Phlickr
These are some tools I've written with Phlickr:
- FavoriteDesktop downloads a random photo from your favorites list, converts it to a Windows bitmap (using ImageMagick's convert tool) and then sets it as your desktop background image.
- PhlickrUploader is my personal script for uploading a directory full of photos, assigning tags and putting them into photosets.
- GetToken will help you retrieve an authorization token for a given API key/secret.
Enabling PHP Modules
Phlickr uses two several of PHP5's extensions, CURL and SimpleXML. In some cases these two extensions may not be enabled by default.
The first step is verify that the modules are not already being loaded. You view a list of the modules using the following command:
Phlickr Installation
Phlickr is released as a PEAR package which you can download from SourceForge.
Prerequisites
Make sure that you are running PHP version 5. You can check the version using the following command:
$ php -v
PHP 5.0.4 (cli) (built: Mar 31 2005 02:45:48)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend TechnologiesAuthentication Token
Flickr uses a numeric value that they call an authentication token to link the permissions a user grants to an application. You'll need to have an [[API key]] and secret.
To obtain an auth token, you can run the following script on a comand line:
<?php
include_once 'Phlickr/Api.php';
// Prevent from enforcing a time limit on this script
//set_time_limit(-1);
ini_set('max_execution_time', 0);
print "This script will help you retrieve a Flickr authorization Token.\n\n";
// Get the user's API key and secret.
print 'API Key: ';
$api_key = trim(fgets(STDIN));
API Key
Flickr's API is open to the public for non-commercial usage but they require that each application have a unique API key. They use the key for two things: application usage tracking and authentication. The tracking lets them block broken applications and that sort of thing. The authentication allows a user to grant an application permissions on their account without giving out their password.
Create a photoset from a tag
This sample demonstrates how to search for photos by tag, sort photos, and create a photoset.
<?php
include_once 'Phlickr/Api.php';
include_once 'Phlickr/AuthedPhotosetList.php';
include_once 'Phlickr/PhotoList.php';
include_once 'Phlickr/PhotoListIterator.php';
require_once 'Phlickr/PhotoSorter.php';
require_once 'Phlickr/PhotoSortStrategy/ByColor.php';
// use the GetToken.php script to generate a config file.
define('API_CONFIG_FILE', './authinfo.cfg');
// the cache file isn't required but if you share it's nice.
define('CACHE_FILE', dirname(__FILE__) . '/cache.tmp');
Uploading a photo
This sample shows how to upload all the JPG files in a directory to Flickr. Take a look at the PhlickrUploader script listed on the tools page for a more complete uploading example.
Sample Code
The following samples should give you an idea how Phlickr works and what you can do with it. There are also some tools written using Phlickr that are useful for both reference and as an idea of how Phlickr can be used in "real world" applications. If you'd like to see other examples please ask.
Most of these examples require that you have an authentication token.
FAQ
- Q: Does Phlickr work with PHP4?
- A: No, [[Phlickr]] uses several of the new features in PHP5. You'll need to try one of the [[other PHP projects]], most are compatible with PHP4.
- Q: Can you recommend a PHP5 web host
Getting started
Here are some suggestions to get you started...
Phlickr
Phlickr is an open source PHP5 based api kit used to access the Flickr API.
I co-authored the book Building Flickr Applications with PHP published Apress.






