Zend_Gdata_Photos.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.gdata.photos">
  4. <title>Using Picasa Web Albums</title>
  5. <para>
  6. Picasa Web Albums is a service which allows users to maintain albums of
  7. their own pictures, and browse the albums and pictures of others.
  8. The API offers a programmatic interface to this service, allowing
  9. users to add to, update, and remove from their albums, as well as
  10. providing the ability to tag and comment on photos.
  11. </para>
  12. <para>
  13. Access to public albums and photos is not restricted by account,
  14. however, a user must be logged in for non-read-only access.
  15. </para>
  16. <para>
  17. For more information on the API, including
  18. instructions for enabling API access, refer to the <ulink
  19. url="http://code.google.com/apis/picasaweb/overview.html">Picasa
  20. Web Albums Data API Overview</ulink>.
  21. </para>
  22. <note>
  23. <title>Authentication</title>
  24. <para>
  25. The API provides authentication via AuthSub (recommended)
  26. and ClientAuth. HTTP connections must be authenticated for write
  27. support, but non-authenticated connections have read-only access.
  28. </para>
  29. </note>
  30. <sect2 id="zend.gdata.photos.connecting">
  31. <title>Connecting To The Service</title>
  32. <para>
  33. The Picasa Web Albums API, like all GData APIs, is based off of the Atom Publishing Protocol (APP),
  34. an XML based format for managing web-based resources. Traffic between a client and the
  35. servers occurs over HTTP and allows for both authenticated and unauthenticated connections.
  36. </para>
  37. <para>
  38. Before any transactions can occur, this connection needs to be made. Creating a connection to the
  39. Picasa servers involves two steps: creating an HTTP client and binding a
  40. <classname>Zend_Gdata_Photos</classname>
  41. service instance to that client.
  42. </para>
  43. <sect3 id="zend.gdata.photos.connecting.authentication">
  44. <title>Authentication</title>
  45. <para>
  46. The Google Picasa API allows access to both public and private photo feeds. Public feeds
  47. do not require authentication, but are read-only and offer reduced functionality. Private feeds
  48. offers the most complete functionality but requires an authenticated connection to the Picasa
  49. servers. There are three authentication schemes that are supported by Google Picasa :
  50. </para>
  51. <itemizedlist>
  52. <listitem>
  53. <para>
  54. <firstterm>ClientAuth</firstterm>
  55. provides direct username/password authentication to the
  56. Picasa servers. Since this scheme requires that users
  57. provide your application with their password, this
  58. authentication is only recommended when other
  59. authentication schemes are insufficient.
  60. </para>
  61. </listitem>
  62. <listitem>
  63. <para>
  64. <firstterm>AuthSub</firstterm>
  65. allows authentication to the Picasa servers via a
  66. Google proxy server. This provides the same level of
  67. convenience as ClientAuth but without the security
  68. risk, making this an ideal choice for web-based
  69. applications.
  70. </para>
  71. </listitem>
  72. </itemizedlist>
  73. <para>
  74. The
  75. <classname>Zend_Gdata</classname>
  76. library provides support for both authentication schemes.
  77. The rest of this chapter will assume that you are familiar the
  78. authentication schemes available and how to create an
  79. appropriate authenticated connection. For more information,
  80. please see section the
  81. <link linkend="zend.gdata.introduction.authentication">Authentication section</link>
  82. of this manual or the
  83. <ulink url="http://code.google.com/apis/gdata/auth.html">Authentication Overview in the Google Data API Developer's Guide</ulink>.
  84. </para>
  85. </sect3>
  86. <sect3 id="zend.gdata.photos.connecting.service">
  87. <title>Creating A Service Instance</title>
  88. <para>
  89. In order to interact with the servers, this library provides the
  90. <classname>Zend_Gdata_Photos</classname> service class. This class provides a common interface to the
  91. Google Data and Atom Publishing Protocol models and assists in marshaling requests to and from
  92. the servers.
  93. </para>
  94. <para>
  95. Once deciding on an authentication scheme, the next step is to create an instance of
  96. <classname>Zend_Gdata_Photos</classname>. The class constructor takes an instance of
  97. <classname>Zend_Http_Client</classname> as a single argument. This provides an interface for AuthSub
  98. and ClientAuth authentication, as both of these require creation of a special authenticated
  99. HTTP client. If no arguments are provided, an unauthenticated instance of
  100. <classname>Zend_Http_Client</classname> will be automatically created.
  101. </para>
  102. <para>The example below shows how to create a service class using ClientAuth authentication:</para>
  103. <programlisting language="php"><![CDATA[
  104. // Parameters for ClientAuth authentication
  105. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  106. $user = "sample.user@gmail.com";
  107. $pass = "pa$$w0rd";
  108. // Create an authenticated HTTP client
  109. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  110. // Create an instance of the service
  111. $service = new Zend_Gdata_Photos($client);
  112. ]]></programlisting>
  113. <para>A service instance using AuthSub can be created in a similar, though slightly more lengthy fashion:</para>
  114. <programlisting language="php"><![CDATA[
  115. session_start();
  116. /**
  117. * Returns the full URL of the current page, based upon env variables
  118. *
  119. * Env variables used:
  120. * $_SERVER['HTTPS'] = (on|off|)
  121. * $_SERVER['HTTP_HOST'] = value of the Host: header
  122. * $_SERVER['SERVER_PORT'] = port number (only used if not http/80,https/443)
  123. * $_SERVER['REQUEST_URI'] = the URI after the method of the HTTP request
  124. *
  125. * @return string Current URL
  126. */
  127. function getCurrentUrl()
  128. {
  129. global $_SERVER;
  130. /**
  131. * Filter php_self to avoid a security vulnerability.
  132. */
  133. $php_request_uri = htmlentities(substr($_SERVER['REQUEST_URI'], 0,
  134. strcspn($_SERVER['REQUEST_URI'], "\n\r")), ENT_QUOTES);
  135. if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
  136. $protocol = 'https://';
  137. } else {
  138. $protocol = 'http://';
  139. }
  140. $host = $_SERVER['HTTP_HOST'];
  141. if ($_SERVER['SERVER_PORT'] != '' &&
  142. (($protocol == 'http://' && $_SERVER['SERVER_PORT'] != '80') ||
  143. ($protocol == 'https://' && $_SERVER['SERVER_PORT'] != '443'))) {
  144. $port = ':' . $_SERVER['SERVER_PORT'];
  145. } else {
  146. $port = '';
  147. }
  148. return $protocol . $host . $port . $php_request_uri;
  149. }
  150. /**
  151. * Returns the AuthSub URL which the user must visit to authenticate requests
  152. * from this application.
  153. *
  154. * Uses getCurrentUrl() to get the next URL which the user will be redirected
  155. * to after successfully authenticating with the Google service.
  156. *
  157. * @return string AuthSub URL
  158. */
  159. function getAuthSubUrl()
  160. {
  161. $next = getCurrentUrl();
  162. $scope = 'http://picasaweb.google.com/data';
  163. $secure = false;
  164. $session = true;
  165. return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure,
  166. $session);
  167. }
  168. /**
  169. * Returns a HTTP client object with the appropriate headers for communicating
  170. * with Google using AuthSub authentication.
  171. *
  172. * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after
  173. * it is obtained. The single use token supplied in the URL when redirected
  174. * after the user succesfully authenticated to Google is retrieved from the
  175. * $_GET['token'] variable.
  176. *
  177. * @return Zend_Http_Client
  178. */
  179. function getAuthSubHttpClient()
  180. {
  181. global $_SESSION, $_GET;
  182. if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
  183. $_SESSION['sessionToken'] =
  184. Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
  185. }
  186. $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
  187. return $client;
  188. }
  189. /**
  190. * Create a new instance of the service, redirecting the user
  191. * to the AuthSub server if necessary.
  192. */
  193. $service = new Zend_Gdata_Photos(getAuthSubHttpClient());
  194. ]]></programlisting>
  195. <para>Finally, an unauthenticated server can be created for use with public feeds:</para>
  196. <programlisting language="php"><![CDATA[
  197. // Create an instance of the service using an unauthenticated HTTP client
  198. $service = new Zend_Gdata_Photos();
  199. ]]></programlisting>
  200. </sect3>
  201. </sect2>
  202. <sect2 id="zend.gdata.photos.queries">
  203. <title>Understanding and Constructing Queries</title>
  204. <para>
  205. The primary method to request data from the service is by constructing a query. There are query
  206. classes for each of the following types:
  207. </para>
  208. <itemizedlist>
  209. <listitem>
  210. <para>
  211. <firstterm>User</firstterm>
  212. is used to specify the user whose data is being searched for, and is specified as a username.
  213. If no user is provided, "default" will be used instead to indicate the currently authenticated
  214. user (if authenticated).
  215. </para>
  216. </listitem>
  217. <listitem>
  218. <para>
  219. <firstterm>Album</firstterm>
  220. is used to specify the album which is being searched for, and is specified as either an id,
  221. or an album name.
  222. </para>
  223. </listitem>
  224. <listitem>
  225. <para>
  226. <firstterm>Photo</firstterm>
  227. is used to specify the photo which is being searched for, and is specified as an id.
  228. </para>
  229. </listitem>
  230. </itemizedlist>
  231. <para>A new <code>UserQuery</code> can be constructed as followed:</para>
  232. <programlisting language="php"><![CDATA[
  233. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  234. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  235. $service = new Zend_Gdata_Photos($client);
  236. $query = new Zend_Gdata_Photos_UserQuery();
  237. $query->setUser("sample.user");
  238. ]]></programlisting>
  239. <para>
  240. For each query, a number of parameters limiting the search can be requested, or specified,
  241. with get(Parameter) and set(Parameter), respectively. They are as follows:
  242. </para>
  243. <itemizedlist>
  244. <listitem>
  245. <para>
  246. <firstterm>Projection</firstterm>
  247. sets the format of the data returned in the feed, as either "api" or "base". Normally,
  248. "api" is desired. The default is "api".
  249. </para>
  250. </listitem>
  251. <listitem>
  252. <para>
  253. <firstterm>Type</firstterm>
  254. sets the type of element to be returned, as either "feed" or "entry". The default is "feed".
  255. </para>
  256. </listitem>
  257. <listitem>
  258. <para>
  259. <firstterm>Access</firstterm>
  260. sets the visibility of items to be returned, as "all", "public", or "private". The default is
  261. "all". Non-public elements will only be returned if the query is searching for the
  262. authenticated user.
  263. </para>
  264. </listitem>
  265. <listitem>
  266. <para>
  267. <firstterm>Tag</firstterm>
  268. sets a tag filter for returned items. When a tag is set, only items tagged with this value
  269. will return.
  270. </para>
  271. </listitem>
  272. <listitem>
  273. <para>
  274. <firstterm>Kind</firstterm>
  275. sets the kind of elements to return. When kind is specified, only entries that match this
  276. value will be returned.
  277. </para>
  278. </listitem>
  279. <listitem>
  280. <para>
  281. <firstterm>ImgMax</firstterm>
  282. sets the maximum image size for entries returned. Only image entries smaller than this value
  283. will be returned.
  284. </para>
  285. </listitem>
  286. <listitem>
  287. <para>
  288. <firstterm>Thumbsize</firstterm>
  289. sets the thumbsize of entries that are returned. Any retrieved entry will have a thumbsize
  290. equal to this value.
  291. </para>
  292. </listitem>
  293. <listitem>
  294. <para>
  295. <firstterm>User</firstterm>
  296. sets the user whose data is being searched for. The default is "default".
  297. </para>
  298. </listitem>
  299. <listitem>
  300. <para>
  301. <firstterm>AlbumId</firstterm>
  302. sets the id of the album being searched for. This element only applies to album and photo queries.
  303. In the case of photo queries, this specifies the album that contains the requested photo. The
  304. album id is mutually exclusive with the album's name. Setting one unsets the other.
  305. </para>
  306. </listitem>
  307. <listitem>
  308. <para>
  309. <firstterm>AlbumName</firstterm>
  310. sets the name of the album being searched for. This element only applies to the album and photo
  311. queries. In the case of photo queries, this specifies the album that contains the requested photo.
  312. The album name is mutually exclusive with the album's id. Setting one unsets the other.
  313. </para>
  314. </listitem>
  315. <listitem>
  316. <para>
  317. <firstterm>PhotoId</firstterm>
  318. sets the id of the photo being searched for. This element only applies to photo queries.
  319. </para>
  320. </listitem>
  321. </itemizedlist>
  322. </sect2>
  323. <sect2 id="zend.gdata.photos.retrieval">
  324. <title>Retrieving Feeds And Entries</title>
  325. <para>
  326. The service has functions to retrieve a feed, or individual entries, for users, albums,
  327. and individual photos.
  328. </para>
  329. <sect3 id="zend.gdata.photos.user_retrieval">
  330. <title>Retrieving A User</title>
  331. <para>
  332. The service supports retrieving a user feed and list of the user's content. If the requested
  333. user is also the authenticated user, entries marked as "<code>hidden</code>" will also be returned.
  334. </para>
  335. <para>The user feed can be accessed by passing the username to the <code>getUserFeed</code> method:</para>
  336. <programlisting language="php"><![CDATA[
  337. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  338. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  339. $service = new Zend_Gdata_Photos($client);
  340. try {
  341. $userFeed = $service->getUserFeed("sample.user");
  342. } catch (Zend_Gdata_App_Exception $e) {
  343. echo "Error: " . $e->getMessage();
  344. }
  345. ]]></programlisting>
  346. <para>Or, the feed can be accessed by constructing a query, first:</para>
  347. <programlisting language="php"><![CDATA[
  348. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  349. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  350. $service = new Zend_Gdata_Photos($client);
  351. $query = new Zend_Gdata_Photos_UserQuery();
  352. $query->setUser("sample.user");
  353. try {
  354. $userFeed = $service->getUserFeed(null, $query);
  355. } catch (Zend_Gdata_App_Exception $e) {
  356. echo "Error: " . $e->getMessage();
  357. }
  358. ]]></programlisting>
  359. <para>Constructing a query also provides the ability to request a user entry object:</para>
  360. <programlisting language="php"><![CDATA[
  361. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  362. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  363. $service = new Zend_Gdata_Photos($client);
  364. $query = new Zend_Gdata_Photos_UserQuery();
  365. $query->setUser("sample.user");
  366. $query->setType("entry");
  367. try {
  368. $userEntry = $service->getUserEntry($query);
  369. } catch (Zend_Gdata_App_Exception $e) {
  370. echo "Error: " . $e->getMessage();
  371. }
  372. ]]></programlisting>
  373. </sect3>
  374. <sect3 id="zend.gdata.photos.album_retrieval">
  375. <title>Retrieving An Album</title>
  376. <para>The service supports retrieving an album feed and a list of the album's content.</para>
  377. <para>
  378. The album feed is accessed by constructing a query object and passing it to <code>getAlbumFeed</code>:
  379. </para>
  380. <programlisting language="php"><![CDATA[
  381. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  382. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  383. $service = new Zend_Gdata_Photos($client);
  384. $query = new Zend_Gdata_Photos_AlbumQuery();
  385. $query->setUser("sample.user");
  386. $query->setAlbumId("1");
  387. try {
  388. $albumFeed = $service->getAlbumFeed($query);
  389. } catch (Zend_Gdata_App_Exception $e) {
  390. echo "Error: " . $e->getMessage();
  391. }
  392. ]]></programlisting>
  393. <para>
  394. Alternatively, the query object can be given an album name with <code>setAlbumName</code>. Setting
  395. the album name is mutually exclusive with setting the album id, and setting one will unset the other.
  396. </para>
  397. <para>Constructing a query also provides the ability to request an album entry object:</para>
  398. <programlisting language="php"><![CDATA[
  399. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  400. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  401. $service = new Zend_Gdata_Photos($client);
  402. $query = new Zend_Gdata_Photos_AlbumQuery();
  403. $query->setUser("sample.user");
  404. $query->setAlbumId("1");
  405. $query->setType("entry");
  406. try {
  407. $albumEntry = $service->getAlbumEntry($query);
  408. } catch (Zend_Gdata_App_Exception $e) {
  409. echo "Error: " . $e->getMessage();
  410. }
  411. ]]></programlisting>
  412. </sect3>
  413. <sect3 id="zend.gdata.photos.photo_retrieval">
  414. <title>Retrieving A Photo</title>
  415. <para>The service supports retrieving a photo feed and a list of associated comments and tags.</para>
  416. <para>
  417. The photo feed is accessed by constructing a query object and passing it to <code>getPhotoFeed</code>:
  418. </para>
  419. <programlisting language="php"><![CDATA[
  420. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  421. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  422. $service = new Zend_Gdata_Photos($client);
  423. $query = new Zend_Gdata_Photos_PhotoQuery();
  424. $query->setUser("sample.user");
  425. $query->setAlbumId("1");
  426. $query->setPhotoId("100");
  427. try {
  428. $photoFeed = $service->getPhotoFeed($query);
  429. } catch (Zend_Gdata_App_Exception $e) {
  430. echo "Error: " . $e->getMessage();
  431. }
  432. ]]></programlisting>
  433. <para>Constructing a query also provides the ability to request a photo entry object:</para>
  434. <programlisting language="php"><![CDATA[
  435. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  436. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  437. $service = new Zend_Gdata_Photos($client);
  438. $query = new Zend_Gdata_Photos_PhotoQuery();
  439. $query->setUser("sample.user");
  440. $query->setAlbumId("1");
  441. $query->setPhotoId("100");
  442. $query->setType("entry");
  443. try {
  444. $photoEntry = $service->getPhotoEntry($query);
  445. } catch (Zend_Gdata_App_Exception $e) {
  446. echo "Error: " . $e->getMessage();
  447. }
  448. ]]></programlisting>
  449. </sect3>
  450. <sect3 id="zend.gdata.photos.comment_retrieval">
  451. <title>Retrieving A Comment</title>
  452. <para>
  453. The service supports retrieving comments from a feed of a different type. By setting a query
  454. to return a kind of "comment", a feed request can return comments associated with a specific user,
  455. album, or photo.
  456. </para>
  457. <para>Performing an action on each of the comments on a given photo can be accomplished as follows:</para>
  458. <programlisting language="php"><![CDATA[
  459. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  460. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  461. $service = new Zend_Gdata_Photos($client);
  462. $query = new Zend_Gdata_Photos_PhotoQuery();
  463. $query->setUser("sample.user");
  464. $query->setAlbumId("1");
  465. $query->setPhotoId("100");
  466. $query->setKind("comment");
  467. try {
  468. $photoFeed = $service->getPhotoFeed($query);
  469. foreach ($photoFeed as $entry) {
  470. if ($entry instanceof Zend_Gdata_Photos_CommentEntry) {
  471. // Do something with the comment
  472. }
  473. }
  474. } catch (Zend_Gdata_App_Exception $e) {
  475. echo "Error: " . $e->getMessage();
  476. }
  477. ]]></programlisting>
  478. </sect3>
  479. <sect3 id="zend.gdata.photos.tag_retrieval">
  480. <title>Retrieving A Tag</title>
  481. <para>
  482. The service supports retrieving tags from a feed of a different type. By setting a query
  483. to return a kind of "tag", a feed request can return tags associated with a specific photo.
  484. </para>
  485. <para>Performing an action on each of the tags on a given photo can be accomplished as follows:</para>
  486. <programlisting language="php"><![CDATA[
  487. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  488. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  489. $service = new Zend_Gdata_Photos($client);
  490. $query = new Zend_Gdata_Photos_PhotoQuery();
  491. $query->setUser("sample.user");
  492. $query->setAlbumId("1");
  493. $query->setPhotoId("100");
  494. $query->setKind("tag");
  495. try {
  496. $photoFeed = $service->getPhotoFeed($query);
  497. foreach ($photoFeed as $entry) {
  498. if ($entry instanceof Zend_Gdata_Photos_TagEntry) {
  499. // Do something with the tag
  500. }
  501. }
  502. } catch (Zend_Gdata_App_Exception $e) {
  503. echo "Error: " . $e->getMessage();
  504. }
  505. ]]></programlisting>
  506. </sect3>
  507. </sect2>
  508. <sect2 id="zend.gdata.photos.creation">
  509. <title>Creating Entries</title>
  510. <para>The service has functions to create albums, photos, comments, and tags.</para>
  511. <sect3 id="zend.gdata.photos.album_creation">
  512. <title>Creating An Album</title>
  513. <para>The service supports creating a new album for an authenticated user:</para>
  514. <programlisting language="php"><![CDATA[
  515. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  516. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  517. $service = new Zend_Gdata_Photos($client);
  518. $entry = new Zend_Gdata_Photos_AlbumEntry();
  519. $entry->setTitle($service->newTitle("test album"));
  520. $service->insertAlbumEntry($entry);
  521. ]]></programlisting>
  522. </sect3>
  523. <sect3 id="zend.gdata.photos.photo_creation">
  524. <title>Creating A Photo</title>
  525. <para>The service supports creating a new photo for an authenticated user:</para>
  526. <programlisting language="php"><![CDATA[
  527. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  528. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  529. $service = new Zend_Gdata_Photos($client);
  530. // $photo is the name of a file uploaded via an HTML form
  531. $fd = $service->newMediaFileSource($photo["tmp_name"]);
  532. $fd->setContentType($photo["type"]);
  533. $entry = new Zend_Gdata_Photos_PhotoEntry();
  534. $entry->setMediaSource($fd);
  535. $entry->setTitle($service->newTitle($photo["name"]));
  536. $albumQuery = new Zend_Gdata_Photos_AlbumQuery;
  537. $albumQuery->setUser("sample.user");
  538. $albumQuery->setAlbumId("1");
  539. $albumEntry = $service->getAlbumEntry($albumQuery);
  540. $service->insertPhotoEntry($entry, $albumEntry);
  541. ]]></programlisting>
  542. </sect3>
  543. <sect3 id="zend.gdata.photos.comment_creation">
  544. <title>Creating A Comment</title>
  545. <para>The service supports creating a new comment for a photo:</para>
  546. <programlisting language="php"><![CDATA[
  547. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  548. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  549. $service = new Zend_Gdata_Photos($client);
  550. $entry = new Zend_Gdata_Photos_CommentEntry();
  551. $entry->setTitle($service->newTitle("comment"));
  552. $entry->setContent($service->newContent("comment"));
  553. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  554. $photoQuery->setUser("sample.user");
  555. $photoQuery->setAlbumId("1");
  556. $photoQuery->setPhotoId("100");
  557. $photoQuery->setType('entry');
  558. $photoEntry = $service->getPhotoEntry($photoQuery);
  559. $service->insertCommentEntry($entry, $photoEntry);
  560. ]]></programlisting>
  561. </sect3>
  562. <sect3 id="zend.gdata.photos.tag_creation">
  563. <title>Creating A Tag</title>
  564. <para>The service supports creating a new tag for a photo:</para>
  565. <programlisting language="php"><![CDATA[
  566. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  567. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  568. $service = new Zend_Gdata_Photos($client);
  569. $entry = new Zend_Gdata_Photos_TagEntry();
  570. $entry->setTitle($service->newTitle("tag"));
  571. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  572. $photoQuery->setUser("sample.user");
  573. $photoQuery->setAlbumId("1");
  574. $photoQuery->setPhotoId("100");
  575. $photoQuery->setType('entry');
  576. $photoEntry = $service->getPhotoEntry($photoQuery);
  577. $service->insertTagEntry($entry, $photoEntry);
  578. ]]></programlisting>
  579. </sect3>
  580. </sect2>
  581. <sect2 id="zend.gdata.photos.deletion">
  582. <title>Deleting Entries</title>
  583. <para>The service has functions to delete albums, photos, comments, and tags.</para>
  584. <sect3 id="zend.gdata.photos.album_deletion">
  585. <title>Deleting An Album</title>
  586. <para>The service supports deleting an album for an authenticated user:</para>
  587. <programlisting language="php"><![CDATA[
  588. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  589. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  590. $service = new Zend_Gdata_Photos($client);
  591. $albumQuery = new Zend_Gdata_Photos_AlbumQuery;
  592. $albumQuery->setUser("sample.user");
  593. $albumQuery->setAlbumId("1");
  594. $albumQuery->setType('entry');
  595. $entry = $service->getAlbumEntry($albumQuery);
  596. $service->deleteAlbumEntry($entry, true);
  597. ]]></programlisting>
  598. </sect3>
  599. <sect3 id="zend.gdata.photos.photo_deletion">
  600. <title>Deleting A Photo</title>
  601. <para>The service supports deleting a photo for an authenticated user:</para>
  602. <programlisting language="php"><![CDATA[
  603. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  604. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  605. $service = new Zend_Gdata_Photos($client);
  606. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  607. $photoQuery->setUser("sample.user");
  608. $photoQuery->setAlbumId("1");
  609. $photoQuery->setPhotoId("100");
  610. $photoQuery->setType('entry');
  611. $entry = $service->getPhotoEntry($photoQuery);
  612. $service->deletePhotoEntry($entry, true);
  613. ]]></programlisting>
  614. </sect3>
  615. <sect3 id="zend.gdata.photos.comment_deletion">
  616. <title>Deleting A Comment</title>
  617. <para>The service supports deleting a comment for an authenticated user:</para>
  618. <programlisting language="php"><![CDATA[
  619. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  620. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  621. $service = new Zend_Gdata_Photos($client);
  622. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  623. $photoQuery->setUser("sample.user");
  624. $photoQuery->setAlbumId("1");
  625. $photoQuery->setPhotoId("100");
  626. $photoQuery->setType('entry');
  627. $path = $photoQuery->getQueryUrl() . '/commentid/' . "1000";
  628. $entry = $service->getCommentEntry($path);
  629. $service->deleteCommentEntry($entry, true);
  630. ]]></programlisting>
  631. </sect3>
  632. <sect3 id="zend.gdata.photos.tag_deletion">
  633. <title>Deleting A Tag</title>
  634. <para>The service supports deleting a tag for an authenticated user:</para>
  635. <programlisting language="php"><![CDATA[
  636. $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  637. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  638. $service = new Zend_Gdata_Photos($client);
  639. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  640. $photoQuery->setUser("sample.user");
  641. $photoQuery->setAlbumId("1");
  642. $photoQuery->setPhotoId("100");
  643. $photoQuery->setKind("tag");
  644. $query = $photoQuery->getQueryUrl();
  645. $photoFeed = $service->getPhotoFeed($query);
  646. foreach ($photoFeed as $entry) {
  647. if ($entry instanceof Zend_Gdata_Photos_TagEntry) {
  648. if ($entry->getContent() == $tagContent) {
  649. $tagEntry = $entry;
  650. }
  651. }
  652. }
  653. $service->deleteTagEntry($tagEntry, true);
  654. ]]></programlisting>
  655. </sect3>
  656. <sect3 id="zend.gdata.photos.optimistic_concurrenty">
  657. <title>Optimistic Concurrency (Notes On Deletion)</title>
  658. <para>
  659. GData feeds, including those of the Picasa Web Albums service, implement optimistic concurrency,
  660. a versioning system that prevents users from overwriting changes, inadvertently. When
  661. deleting a entry through the service class, if the entry has been modified since it was
  662. last fetched, an exception will be thrown, unless explicitly set otherwise (in which case
  663. the deletion is retried on the updated entry).
  664. </para>
  665. <para>
  666. An example of how to handle versioning during a deletion is shown by <code>deleteAlbumEntry</code>:
  667. </para>
  668. <programlisting language="php"><![CDATA[
  669. // $album is the albumEntry to be deleted
  670. try {
  671. $this->delete($album);
  672. } catch (Zend_Gdata_App_HttpException $e) {
  673. if ($e->getMessage()->getStatus() === 409) {
  674. $entry =
  675. new Zend_Gdata_Photos_AlbumEntry($e->getMessage()->getBody());
  676. $this->delete($entry->getLink('edit')->href);
  677. } else {
  678. throw $e;
  679. }
  680. }
  681. ]]></programlisting>
  682. </sect3>
  683. </sect2>
  684. </sect1>