From 06f945f27840b53e57795dadbc38e76f7e11ab1c Mon Sep 17 00:00:00 2001 From: Horus3 Date: Mon, 24 Feb 2014 16:42:14 +0100 Subject: init --- .../manual/core/en/zend.gdata.photos.html | 959 +++++++++++++++++++++ 1 file changed, 959 insertions(+) create mode 100644 zend/documentation/manual/core/en/zend.gdata.photos.html (limited to 'zend/documentation/manual/core/en/zend.gdata.photos.html') diff --git a/zend/documentation/manual/core/en/zend.gdata.photos.html b/zend/documentation/manual/core/en/zend.gdata.photos.html new file mode 100644 index 0000000..036cd9b --- /dev/null +++ b/zend/documentation/manual/core/en/zend.gdata.photos.html @@ -0,0 +1,959 @@ + + + + + Using Picasa Web Albums - Zend Framework Manual + + + + + + + + +
+ + + + + + + + +
+ Using Google Apps Provisioning + + + + +
+
+

Using Picasa Web Albums

+ + +

+ Picasa Web Albums is a service which allows users to maintain albums of + their own pictures, and browse the albums and pictures of others. + The API offers a programmatic interface to this service, allowing + users to add to, update, and remove from their albums, as well as + providing the ability to tag and comment on photos. +

+ +

+ Access to public albums and photos is not restricted by account, + however, a user must be logged in for non-read-only access. +

+ +

+ For more information on the API, including + instructions for enabling API access, refer to the » Picasa + Web Albums Data API Overview. +

+ +

Note: Authentication
+ + + + The API provides authentication via AuthSub (recommended) + and ClientAuth. HTTP connections must be authenticated for write + support, but non-authenticated connections have read-only access. +
+

+ +

Connecting To The Service

+ + +

+ The Picasa Web Albums API, like all GData APIs, is + based off of the Atom Publishing Protocol (APP), an XML based format + for managing web-based resources. Traffic between a client and the servers occurs over + HTTP and allows for both authenticated and unauthenticated + connections. +

+ +

+ Before any transactions can occur, this connection needs to be made. Creating a + connection to the Picasa servers involves two steps: creating an HTTP + client and binding a Zend_Gdata_Photos + service instance to that client. +

+ +

Authentication

+ + +

+ The Google Picasa API allows access to both public and private + photo feeds. Public feeds do not require authentication, but are read-only and offer + reduced functionality. Private feeds offers the most complete functionality but + requires an authenticated connection to the Picasa servers. There are three + authentication schemes that are supported by Google Picasa : +

+ +
    +
  • +

    + ClientAuth + provides direct username/password authentication to the + Picasa servers. Since this scheme requires that users + provide your application with their password, this + authentication is only recommended when other + authentication schemes are insufficient. +

    +
  • + +
  • +

    + AuthSub + allows authentication to the Picasa servers via a + Google proxy server. This provides the same level of + convenience as ClientAuth but without the security + risk, making this an ideal choice for web-based + applications. +

    +
  • +
+ +

+ The + Zend_Gdata + library provides support for both authentication schemes. + The rest of this chapter will assume that you are familiar the + authentication schemes available and how to create an + appropriate authenticated connection. For more information, + please see section the + Authentication section + of this manual or the » Authentication Overview in the + Google Data API Developer's Guide. +

+
+ +

Creating A Service Instance

+ + +

+ In order to interact with the servers, this library provides the + Zend_Gdata_Photos service class. This class provides a common + interface to the Google Data and Atom Publishing Protocol models and assists in + marshaling requests to and from the servers. +

+ +

+ Once deciding on an authentication scheme, the next step is to create an instance of + Zend_Gdata_Photos. The class constructor takes an instance of + Zend_Http_Client as a single argument. This provides an + interface for AuthSub and ClientAuth authentication, as both of these require + creation of a special authenticated HTTP client. If no arguments + are provided, an unauthenticated instance of Zend_Http_Client + will be automatically created. +

+ +

+ The example below shows how to create a service class using ClientAuth + authentication: +

+ +
  1. // Parameters for ClientAuth authentication
  2. +
  3. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  4. +
  5. $user = "sample.user@gmail.com";
  6. +
  7. $pass = "pa$$w0rd";
  8. +
  9.  
  10. +
  11. // Create an authenticated HTTP client
  12. +
  13. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  14. +
  15.  
  16. +
  17. // Create an instance of the service
  18. +
  19. $service = new Zend_Gdata_Photos($client);
+ + +

+ A service instance using AuthSub can be created in a similar, though slightly more + lengthy fashion: +

+ +
  1. +
  2.  
  3. +
  4. /**
  5. +
  6. * Returns the full URL of the current page, based upon env variables
  7. +
  8. *
  9. +
  10. * Env variables used:
  11. +
  12. * $_SERVER['HTTPS'] = (on|off|)
  13. +
  14. * $_SERVER['HTTP_HOST'] = value of the Host: header
  15. +
  16. * $_SERVER['SERVER_PORT'] = port number (only used if not http/80,https/443)
  17. +
  18. * $_SERVER['REQUEST_URI'] = the URI after the method of the HTTP request
  19. +
  20. *
  21. +
  22. * @return string Current URL
  23. +
  24. */
  25. +
  26. function getCurrentUrl()
  27. +
  28. {
  29. +
  30.     global $_SERVER;
  31. +
  32.  
  33. +
  34.     /**
  35. +
  36.      * Filter php_self to avoid a security vulnerability.
  37. +
  38.      */
  39. +
  40.     $php_request_uri = htmlentities(substr($_SERVER['REQUEST_URI'], 0,
  41. +
  42.     strcspn($_SERVER['REQUEST_URI'], "\n\r")), ENT_QUOTES);
  43. +
  44.  
  45. +
  46.     if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
  47. +
  48.         $protocol = 'https://';
  49. +
  50.     } else {
  51. +
  52.         $protocol = 'http://';
  53. +
  54.     }
  55. +
  56.     $host = $_SERVER['HTTP_HOST'];
  57. +
  58.     if ($_SERVER['SERVER_PORT'] != '' &&
  59. +
  60.         (($protocol == 'http://' && $_SERVER['SERVER_PORT'] != '80') ||
  61. +
  62.         ($protocol == 'https://' && $_SERVER['SERVER_PORT'] != '443'))) {
  63. +
  64.             $port = ':' . $_SERVER['SERVER_PORT'];
  65. +
  66.     } else {
  67. +
  68.         $port = '';
  69. +
  70.     }
  71. +
  72.     return $protocol . $host . $port . $php_request_uri;
  73. +
  74. }
  75. +
  76.  
  77. +
  78. /**
  79. +
  80. * Returns the AuthSub URL which the user must visit to authenticate requests
  81. +
  82. * from this application.
  83. +
  84. *
  85. +
  86. * Uses getCurrentUrl() to get the next URL which the user will be redirected
  87. +
  88. * to after successfully authenticating with the Google service.
  89. +
  90. *
  91. +
  92. * @return string AuthSub URL
  93. +
  94. */
  95. +
  96. function getAuthSubUrl()
  97. +
  98. {
  99. +
  100.     $next = getCurrentUrl();
  101. +
  102.     $scope = 'http://picasaweb.google.com/data';
  103. +
  104.     $secure = false;
  105. +
  106.     $session = true;
  107. +
  108.     return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure,
  109. +
  110.         $session);
  111. +
  112. }
  113. +
  114.  
  115. +
  116. /**
  117. +
  118. * Returns a HTTP client object with the appropriate headers for communicating
  119. +
  120. * with Google using AuthSub authentication.
  121. +
  122. *
  123. +
  124. * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after
  125. +
  126. * it is obtained. The single use token supplied in the URL when redirected
  127. +
  128. * after the user succesfully authenticated to Google is retrieved from the
  129. +
  130. * $_GET['token'] variable.
  131. +
  132. *
  133. +
  134. * @return Zend_Http_Client
  135. +
  136. */
  137. +
  138. function getAuthSubHttpClient()
  139. +
  140. {
  141. +
  142.     global $_SESSION, $_GET;
  143. +
  144.     if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
  145. +
  146.         $_SESSION['sessionToken'] =
  147. +
  148.             Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
  149. +
  150.     }
  151. +
  152.     $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
  153. +
  154.     return $client;
  155. +
  156. }
  157. +
  158.  
  159. +
  160. /**
  161. +
  162. * Create a new instance of the service, redirecting the user
  163. +
  164. * to the AuthSub server if necessary.
  165. +
  166. */
  167. +
  168. $service = new Zend_Gdata_Photos(getAuthSubHttpClient());
+ + +

+ Finally, an unauthenticated server can be created for use with public feeds: +

+ +
  1. // Create an instance of the service using an unauthenticated HTTP client
  2. +
  3. $service = new Zend_Gdata_Photos();
+ +
+
+ +

Understanding and Constructing Queries

+ + +

+ The primary method to request data from the service is by constructing a query. There + are query classes for each of the following types: +

+ +
    +
  • +

    + User is used to specify the user whose data is being + searched for, and is specified as a username. if no user is provided, "default" + will be used instead to indicate the currently authenticated user (if + authenticated). +

    +
  • + +
  • +

    + Album is used to specify the album which is being + searched for, and is specified as either an id, or an album name. +

    +
  • + +
  • +

    + Photo is used to specify the photo which is being + searched for, and is specified as an id. +

    +
  • +
+ +

A new UserQuery can be constructed as followed:

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $query = new Zend_Gdata_Photos_UserQuery();
  10. +
  11. $query->setUser("sample.user");
+ + +

+ for each query, a number of parameters limiting the search can be requested, or + specified, with get(Parameter) and set(Parameter), respectively. They are as follows: +

+ +
    +
  • +

    + Projection sets the format of the data returned in the + feed, as either "api" or "base". Normally, "api" is desired. The default is + "api". +

    +
  • + +
  • +

    + Type sets the type of element to be returned, as either + "feed" or "entry". The default is "feed". +

    +
  • + +
  • +

    + Access sets the visibility of items to be returned, as + "all", "public", or "private". The default is "all". Non-public elements will + only be returned if the query is searching for the authenticated user. +

    +
  • + +
  • +

    + Tag sets a tag filter for returned items. When a tag is + set, only items tagged with this value will return. +

    +
  • + +
  • +

    + Kind sets the kind of elements to return. When kind is + specified, only entries that match this value will be returned. +

    +
  • + +
  • +

    + ImgMax sets the maximum image size for entries returned. + Only image entries smaller than this value will be returned. +

    +
  • + +
  • +

    + Thumbsize sets the thumbsize of entries that are + returned. Any retrieved entry will have a thumbsize equal to this value. +

    +
  • + +
  • +

    + User sets the user whose data is being searched for. The + default is "default". +

    +
  • + +
  • +

    + AlbumId sets the id of the album being searched for. This + element only applies to album and photo queries. In the case of photo queries, + this specifies the album that contains the requested photo. The album id is + mutually exclusive with the album's name. Setting one unsets the other. +

    +
  • + +
  • +

    + AlbumName sets the name of the album being searched for. + This element only applies to the album and photo queries. In the case of photo + queries, this specifies the album that contains the requested photo. The album + name is mutually exclusive with the album's id. Setting one unsets the other. +

    +
  • + +
  • +

    + PhotoId sets the id of the photo being searched for. This + element only applies to photo queries. +

    +
  • +
+
+ +

Retrieving Feeds And Entries

+ + +

+ The service has functions to retrieve a feed, or individual entries, for users, albums, + and individual photos. +

+ +

Retrieving A User

+ + +

+ The service supports retrieving a user feed and list of the user's content. If the + requested user is also the authenticated user, entries marked as + "hidden" will also be returned. +

+ +

+ The user feed can be accessed by passing the username to the + getUserFeed() method: +

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. try {
  10. +
  11.     $userFeed = $service->getUserFeed("sample.user");
  12. +
  13. } catch (Zend_Gdata_App_Exception $e) {
  14. +
  15.     echo "Error: " . $e->getMessage();
  16. +
  17. }
+ + +

Or, the feed can be accessed by constructing a query, first:

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $query = new Zend_Gdata_Photos_UserQuery();
  10. +
  11. $query->setUser("sample.user");
  12. +
  13.  
  14. +
  15. try {
  16. +
  17.     $userFeed = $service->getUserFeed(null, $query);
  18. +
  19. } catch (Zend_Gdata_App_Exception $e) {
  20. +
  21.     echo "Error: " . $e->getMessage();
  22. +
  23. }
+ + +

+ Constructing a query also provides the ability to request a user entry object: +

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $query = new Zend_Gdata_Photos_UserQuery();
  10. +
  11. $query->setUser("sample.user");
  12. +
  13. $query->setType("entry");
  14. +
  15.  
  16. +
  17. try {
  18. +
  19.     $userEntry = $service->getUserEntry($query);
  20. +
  21. } catch (Zend_Gdata_App_Exception $e) {
  22. +
  23.     echo "Error: " . $e->getMessage();
  24. +
  25. }
+ +
+ +

Retrieving An Album

+ + +

+ The service supports retrieving an album feed and a list of the album's content. +

+ +

+ The album feed is accessed by constructing a query object and passing it to + getAlbumFeed(): +

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $query = new Zend_Gdata_Photos_AlbumQuery();
  10. +
  11. $query->setUser("sample.user");
  12. +
  13. $query->setAlbumId("1");
  14. +
  15.  
  16. +
  17. try {
  18. +
  19.     $albumFeed = $service->getAlbumFeed($query);
  20. +
  21. } catch (Zend_Gdata_App_Exception $e) {
  22. +
  23.     echo "Error: " . $e->getMessage();
  24. +
  25. }
+ + +

+ Alternatively, the query object can be given an album name with + setAlbumName(). Setting the album name is mutually + exclusive with setting the album id, and setting one will unset the other. +

+ +

+ Constructing a query also provides the ability to request an album entry object: +

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $query = new Zend_Gdata_Photos_AlbumQuery();
  10. +
  11. $query->setUser("sample.user");
  12. +
  13. $query->setAlbumId("1");
  14. +
  15. $query->setType("entry");
  16. +
  17.  
  18. +
  19. try {
  20. +
  21.     $albumEntry = $service->getAlbumEntry($query);
  22. +
  23. } catch (Zend_Gdata_App_Exception $e) {
  24. +
  25.     echo "Error: " . $e->getMessage();
  26. +
  27. }
+ +
+ +

Retrieving A Photo

+ + +

+ The service supports retrieving a photo feed and a list of associated comments and + tags. +

+ +

+ The photo feed is accessed by constructing a query object and passing it to + getPhotoFeed(): +

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $query = new Zend_Gdata_Photos_PhotoQuery();
  10. +
  11. $query->setUser("sample.user");
  12. +
  13. $query->setAlbumId("1");
  14. +
  15. $query->setPhotoId("100");
  16. +
  17.  
  18. +
  19. try {
  20. +
  21.     $photoFeed = $service->getPhotoFeed($query);
  22. +
  23. } catch (Zend_Gdata_App_Exception $e) {
  24. +
  25.     echo "Error: " . $e->getMessage();
  26. +
  27. }
+ + +

+ Constructing a query also provides the ability to request a photo entry object: +

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $query = new Zend_Gdata_Photos_PhotoQuery();
  10. +
  11. $query->setUser("sample.user");
  12. +
  13. $query->setAlbumId("1");
  14. +
  15. $query->setPhotoId("100");
  16. +
  17. $query->setType("entry");
  18. +
  19.  
  20. +
  21. try {
  22. +
  23.     $photoEntry = $service->getPhotoEntry($query);
  24. +
  25. } catch (Zend_Gdata_App_Exception $e) {
  26. +
  27.     echo "Error: " . $e->getMessage();
  28. +
  29. }
+ +
+ +

Retrieving A Comment

+ + +

+ The service supports retrieving comments from a feed of a different type. By setting + a query to return a kind of "comment", a feed request can return comments associated + with a specific user, album, or photo. +

+ +

+ Performing an action on each of the comments on a given photo can be accomplished + as follows: +

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $query = new Zend_Gdata_Photos_PhotoQuery();
  10. +
  11. $query->setUser("sample.user");
  12. +
  13. $query->setAlbumId("1");
  14. +
  15. $query->setPhotoId("100");
  16. +
  17. $query->setKind("comment");
  18. +
  19.  
  20. +
  21. try {
  22. +
  23.     $photoFeed = $service->getPhotoFeed($query);
  24. +
  25.  
  26. +
  27.     foreach ($photoFeed as $entry) {
  28. +
  29.         if ($entry instanceof Zend_Gdata_Photos_CommentEntry) {
  30. +
  31.             // Do something with the comment
  32. +
  33.         }
  34. +
  35.     }
  36. +
  37. } catch (Zend_Gdata_App_Exception $e) {
  38. +
  39.     echo "Error: " . $e->getMessage();
  40. +
  41. }
+ +
+ +

Retrieving A Tag

+ + +

+ The service supports retrieving tags from a feed of a different type. By setting a + query to return a kind of "tag", a feed request can return tags associated with a + specific photo. +

+ +

+ Performing an action on each of the tags on a given photo can be accomplished as + follows: +

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $query = new Zend_Gdata_Photos_PhotoQuery();
  10. +
  11. $query->setUser("sample.user");
  12. +
  13. $query->setAlbumId("1");
  14. +
  15. $query->setPhotoId("100");
  16. +
  17. $query->setKind("tag");
  18. +
  19.  
  20. +
  21. try {
  22. +
  23.     $photoFeed = $service->getPhotoFeed($query);
  24. +
  25.  
  26. +
  27.     foreach ($photoFeed as $entry) {
  28. +
  29.         if ($entry instanceof Zend_Gdata_Photos_TagEntry) {
  30. +
  31.             // Do something with the tag
  32. +
  33.         }
  34. +
  35.     }
  36. +
  37. } catch (Zend_Gdata_App_Exception $e) {
  38. +
  39.     echo "Error: " . $e->getMessage();
  40. +
  41. }
+ +
+
+ +

Creating Entries

+ + +

The service has functions to create albums, photos, comments, and tags.

+ +

Creating An Album

+ + +

The service supports creating a new album for an authenticated user:

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $entry = new Zend_Gdata_Photos_AlbumEntry();
  10. +
  11. $entry->setTitle($service->newTitle("test album"));
  12. +
  13.  
  14. +
  15. $service->insertAlbumEntry($entry);
+ +
+ +

Creating A Photo

+ + +

The service supports creating a new photo for an authenticated user:

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. // $photo is the name of a file uploaded via an HTML form
  10. +
  11.  
  12. +
  13. $fd = $service->newMediaFileSource($photo["tmp_name"]);
  14. +
  15. $fd->setContentType($photo["type"]);
  16. +
  17.  
  18. +
  19. $entry = new Zend_Gdata_Photos_PhotoEntry();
  20. +
  21. $entry->setMediaSource($fd);
  22. +
  23. $entry->setTitle($service->newTitle($photo["name"]));
  24. +
  25.  
  26. +
  27. $albumQuery = new Zend_Gdata_Photos_AlbumQuery;
  28. +
  29. $albumQuery->setUser("sample.user");
  30. +
  31. $albumQuery->setAlbumId("1");
  32. +
  33.  
  34. +
  35. $albumEntry = $service->getAlbumEntry($albumQuery);
  36. +
  37.  
  38. +
  39. $service->insertPhotoEntry($entry, $albumEntry);
+ +
+ +

Creating A Comment

+ + +

The service supports creating a new comment for a photo:

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $entry = new Zend_Gdata_Photos_CommentEntry();
  10. +
  11. $entry->setTitle($service->newTitle("comment"));
  12. +
  13. $entry->setContent($service->newContent("comment"));
  14. +
  15.  
  16. +
  17. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  18. +
  19. $photoQuery->setUser("sample.user");
  20. +
  21. $photoQuery->setAlbumId("1");
  22. +
  23. $photoQuery->setPhotoId("100");
  24. +
  25. $photoQuery->setType('entry');
  26. +
  27.  
  28. +
  29. $photoEntry = $service->getPhotoEntry($photoQuery);
  30. +
  31.  
  32. +
  33. $service->insertCommentEntry($entry, $photoEntry);
+ +
+ +

Creating A Tag

+ + +

The service supports creating a new tag for a photo:

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $entry = new Zend_Gdata_Photos_TagEntry();
  10. +
  11. $entry->setTitle($service->newTitle("tag"));
  12. +
  13.  
  14. +
  15. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  16. +
  17. $photoQuery->setUser("sample.user");
  18. +
  19. $photoQuery->setAlbumId("1");
  20. +
  21. $photoQuery->setPhotoId("100");
  22. +
  23. $photoQuery->setType('entry');
  24. +
  25.  
  26. +
  27. $photoEntry = $service->getPhotoEntry($photoQuery);
  28. +
  29.  
  30. +
  31. $service->insertTagEntry($entry, $photoEntry);
+ +
+
+ +

Deleting Entries

+ + +

The service has functions to delete albums, photos, comments, and tags.

+ +

Deleting An Album

+ + +

The service supports deleting an album for an authenticated user:

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $albumQuery = new Zend_Gdata_Photos_AlbumQuery;
  10. +
  11. $albumQuery->setUser("sample.user");
  12. +
  13. $albumQuery->setAlbumId("1");
  14. +
  15. $albumQuery->setType('entry');
  16. +
  17.  
  18. +
  19. $entry = $service->getAlbumEntry($albumQuery);
  20. +
  21.  
  22. +
  23. $service->deleteAlbumEntry($entry, true);
+ +
+ +

Deleting A Photo

+ + +

The service supports deleting a photo for an authenticated user:

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  10. +
  11. $photoQuery->setUser("sample.user");
  12. +
  13. $photoQuery->setAlbumId("1");
  14. +
  15. $photoQuery->setPhotoId("100");
  16. +
  17. $photoQuery->setType('entry');
  18. +
  19.  
  20. +
  21. $entry = $service->getPhotoEntry($photoQuery);
  22. +
  23.  
  24. +
  25. $service->deletePhotoEntry($entry, true);
+ +
+ +

Deleting A Comment

+ + +

The service supports deleting a comment for an authenticated user:

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  10. +
  11. $photoQuery->setUser("sample.user");
  12. +
  13. $photoQuery->setAlbumId("1");
  14. +
  15. $photoQuery->setPhotoId("100");
  16. +
  17. $photoQuery->setType('entry');
  18. +
  19.  
  20. +
  21. $path = $photoQuery->getQueryUrl() . '/commentid/' . "1000";
  22. +
  23.  
  24. +
  25. $entry = $service->getCommentEntry($path);
  26. +
  27.  
  28. +
  29. $service->deleteCommentEntry($entry, true);
+ +
+ +

Deleting A Tag

+ + +

The service supports deleting a tag for an authenticated user:

+ +
  1. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  2. +
  3. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  4. +
  5. $service = new Zend_Gdata_Photos($client);
  6. +
  7.  
  8. +
  9. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  10. +
  11. $photoQuery->setUser("sample.user");
  12. +
  13. $photoQuery->setAlbumId("1");
  14. +
  15. $photoQuery->setPhotoId("100");
  16. +
  17. $photoQuery->setKind("tag");
  18. +
  19. $query = $photoQuery->getQueryUrl();
  20. +
  21.  
  22. +
  23. $photoFeed = $service->getPhotoFeed($query);
  24. +
  25.  
  26. +
  27. foreach ($photoFeed as $entry) {
  28. +
  29.     if ($entry instanceof Zend_Gdata_Photos_TagEntry) {
  30. +
  31.         if ($entry->getContent() == $tagContent) {
  32. +
  33.             $tagEntry = $entry;
  34. +
  35.         }
  36. +
  37.     }
  38. +
  39. }
  40. +
  41.  
  42. +
  43. $service->deleteTagEntry($tagEntry, true);
+ +
+ +

Optimistic Concurrency (Notes On Deletion)

+ + +

+ GData feeds, including those of the Picasa Web Albums service, implement optimistic + concurrency, a versioning system that prevents users from overwriting changes, + inadvertently. When deleting a entry through the service class, if the entry has + been modified since it was last fetched, an exception will be thrown, unless + explicitly set otherwise (in which case the deletion is retried on the updated + entry). +

+ +

+ An example of how to handle versioning during a deletion is shown by + deleteAlbumEntry(): +

+ +
  1. // $album is the albumEntry to be deleted
  2. +
  3. try {
  4. +
  5.     $this->delete($album);
  6. +
  7. } catch (Zend_Gdata_App_HttpException $e) {
  8. +
  9.     if ($e->getMessage()->getStatus() === 409) {
  10. +
  11.         $entry =
  12. +
  13.             new Zend_Gdata_Photos_AlbumEntry($e->getMessage()->getBody());
  14. +
  15.         $this->delete($entry->getLink('edit')->href);
  16. +
  17.     } else {
  18. +
  19.         throw $e;
  20. +
  21.     }
  22. +
  23. }
+ +
+
+
+
+ + + + + + + + + +
+ Using Google Apps Provisioning + + + + +
+
+ +
+ + \ No newline at end of file -- cgit v1.2.3