ZendService\Flickr

ZendServiceFlickr

Introduction

ZendService\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.

Simple Flickr Photo Search

1
2
3
4
5
6
7
$flickr = new ZendService\Flickr\Flickr('MY_API_KEY');

$results = $flickr->tagSearch("php");

foreach ($results as $result) {
    echo $result->title . '<br />';
}

Note

Optional parameter

tagSearch() accepts an optional second parameter as an array of options.

Finding Flickr Users’ Photos and Information

ZendService\Flickr\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 ZendService\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.

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:

1
2
3
4
5
6
7
$flickr = new ZendService\Flickr('MY_API_KEY');

$results = $flickr->userSearch($userEmail);

foreach ($results as $result) {
    echo $result->title . '<br />';
}

Finding photos From a Group Pool

ZendService\Flickr\Flickr allows to retrieve a group’s pool photos based on the group ID. Use the groupPoolGetPhotos() method:

Retrieving a Group’s Pool Photos by Group ID

1
2
3
4
5
6
7
$flickr = new ZendService\Flickr\Flickr('MY_API_KEY');

    $results = $flickr->groupPoolGetPhotos($groupId);

    foreach ($results as $result) {
        echo $result->title . '<br />';
    }

Note

Optional parameter

groupPoolGetPhotos() accepts an optional second parameter as an array of options.

Retrieving Flickr Image Details

ZendService\Flickr\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:

Retrieving Flickr Image Details

Once you have a Flickr image ID, it is a simple matter to fetch information about the image:

1
2
3
4
5
6
$flickr = new ZendService\Flickr\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";

ZendServiceFlickr Result Classes

The following classes are all returned by tagSearch() and userSearch():

ZendServiceFlickrResultSet

Represents a set of Results from a Flickr search.

Note

Implements the SeekableIterator interface for easy iteration (e.g., using foreach()), as well as direct access to a specific result using seek().

Properties

ZendServiceFlickrResultSet Properties
Name Type Description
totalResultsAvailable int Total Number of Results available
totalResultsReturned int Total Number of Results returned
firstResultPosition int The offset in the total result set of this result set

ZendServiceFlickrResultSet::totalResults()

int:totalResults()

Returns the total number of results in this result set.

Back to Class List

ZendServiceFlickrResult

A single Image result from a Flickr query

ZendServiceFlickrImage

Represents an Image returned by a Flickr search.

Properties

ZendServiceFlickrImage Properties
Name Type Description
uri string URI for the original image
clickUri string Clickable URI (i.e. the Flickr page) for the image
width int Width of the Image
height int Height of the Image

Back to Class List

blog comments powered by Disqus