Zend_Service_Flickr
is a simple API for using the Flickr REST Web Service. In order to use
the Flickr web services, you must have an API key. To obtain a key and for more information about the
Flickr REST Web Service, please visit the
Flickr API Documentation.
In the following example, we use the tagSearch()
method to search for photos having "php"
in the tags.
Example 29.24. Simple Flickr Photo Search
<?php require_once 'Zend/Service/Flickr.php'; $flickr = new Zend_Service_Flickr('MY_API_KEY'); $results = $flickr->tagSearch("php"); foreach ($results as $result) { echo $result->title . '<br />'; } ?>
Optional parameter | |
---|---|
|
Zend_Service_Flickr
provides several ways to get information about Flickr users:
userSearch()
: Accepts a string query of space-delimited tags and an optional second
parameter as an array of search options, and returns a set of photos as a
Zend_Service_Flickr_ResultSet
object.
getIdByUsername()
: Returns a string user ID associated with the given username string.
getIdByEmail()
: Returns a string user ID associated with the given email address
string.
Example 29.25. Finding a Flickr User's Public Photos by E-Mail Address
In this example, we have a Flickr user's e-mail address, and we search for the user's public photos by
using the userSearch()
method:
<?php require_once 'Zend/Service/Flickr.php'; $flickr = new Zend_Service_Flickr('MY_API_KEY'); $results = $flickr->userSearch($userEmail); foreach ($results as $result) { echo $result->title . '<br />'; } ?>
Zend_Service_Flickr
makes it quick and easy to get an image's details based on a given image
ID. Just use the getImageDetails()
method, as in the following example:
Example 29.26. Retrieving Flickr Image Details
Once you have a Flickr image ID, it is a simple matter to fetch information about the image:
<?php require_once 'Zend/Service/Flickr.php'; $flickr = new Zend_Service_Flickr('MY_API_KEY'); $image = $flickr->getImageDetails($imageId); echo "Image ID $imageId is $image->width x $image->height pixels.<br />\n"; echo "<a href=\"$image->clickUri\">Click for Image</a>\n"; ?>
The following classes are all returned by tagSearch()
and userSearch()
:
Represents a set of Results from a Flickr search.
Note | |
---|---|
Implements the |
int totalResults();
Returns the total number of results in this result set.
A single Image result from a Flickr query
Table 29.13. Zend_Service_Flickr_Result Properties
Name | Type | Description |
---|---|---|
id | string | Image ID |
owner | string | The photo owner's NSID. |
secret | string | A key used in url construction. |
server | string | The servername to use for URL construction. |
title | string | The photo's title. |
ispublic | string | The photo is public. |
isfriend | string | The photo is visible to you because you are a friend of the owner. |
isfamily | string | The photo is visible to you because you are family of the owner. |
license | string | The license the photo is available under. |
dateupload | string | The date the photo was uploaded. |
datetaken | string | The date the photo was taken. |
ownername | string | The screenname of the owner. |
iconserver | string | The server used in assembling icon URLs. |
Square | Zend_Service_Flickr_Image | A 75x75 thumbnail of the image. |
Thumbnail | Zend_Service_Flickr_Image | A 100 pixel thumbnail of the image. |
Small | Zend_Service_Flickr_Image | A 240 pixel version of the image. |
Medium | Zend_Service_Flickr_Image | A 500 pixel version of the image. |
Large | Zend_Service_Flickr_Image | A 640 pixel version of the image. |
Original | Zend_Service_Flickr_Image | The original image. |