16.4. Zend_Service_Flickr
السابق | فصل 16. Zend_Service | التالي

## 16.4. Zend_Service_Flickr

### 16.4.1. Introduction to Searching Flickr

`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.

مثال 16.8. 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 />';
    }
    ?>

| ملاحظة
`tagSearch()` accepts an optional second parameter as an array of options.

### 16.4.2. Finding Flickr Users

`Zend_Service_Flickr` provides three various ways to get Flickr user information:

- `userSearch()`: Accepts a string query of space-delimited tags and an optional second parameter as an array of search options, and returns 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.

مثال 16.9. Finding a Flickr User by E-Mail Address

In this example, we have a Flickr user's e-mail address, and we fetch the user information 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 />';
    }
    ?>

### 16.4.3. Retrieving Flickr Image Details

`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:

مثال 16.10. 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";
    ?>

### 16.4.4. Zend_Service_Flickr Classes

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

- `Zend_Service_Flickr_ResultSet`

- `Zend_Service_Flickr_Result`

- `Zend_Service_Flickr_Image`

#### 16.4.4.1. Zend_Service_Flickr_ResultSet

Represents a set of Results from a Flickr search.

| ملاحظة
Implements the `SeekableIterator` for easy iteration (e.g., using `foreach` ), as well as direct access to a specific result using `seek()` .

##### 16.4.4.1.1. Properties

جدول 16.10. Zend_Service_Flickr_ResultSet 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

##### 16.4.4.1.2. Zend_Service_Flickr_ResultSet::totalResults()

`int totalResults();`

Returns the total number of results in this result set.

Back to Class List

#### 16.4.4.2. Zend_Service_Flickr_Result

A single Image result from a Flickr query

##### 16.4.4.2.1. Properties

جدول 16.11. Zend_Service_Flickr_Result Properties

Name | Type | Description
--- | --- | ---
id | int | Image ID
owner | int | 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 | boolean | The photo is public.
isfriend | boolean | The photo is visible to you because you are a friend of the owner.
isfamily | boolean | The photo is visible to you because you are family of the owner.
license | string | The license the photo is available under.
date_upload | string | The date the photo was uploaded.
date_taken | string | The date the photo was taken.
owner_name | string | The screenname of the owner.
icon_server | 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.

Back to Class List

#### 16.4.4.3. Zend_Service_Flickr_Image

Represents an Image returned by a Flickr search.

##### 16.4.4.3.1. Properties

جدول 16.12. Zend_Service_Flickr_Image 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

السابق | أعلى | التالي
16.3. Zend_Service_Amazon | البداية | 16.5. Zend_Service_Yahoo