Zend_Gdata-Introduction.xml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.gdata.introduction">
  4. <title>Introduction</title>
  5. <para>
  6. Google Data <acronym>API</acronym>s provide programmatic interface to some of Google's
  7. online services. The Google data Protocol is based upon the <ulink
  8. url="http://ietfreport.isoc.org/idref/draft-ietf-atompub-protocol/">Atom Publishing
  9. Protocol</ulink> and allows client applications to retrieve data matching queries,
  10. post data, update data and delete data using standard <acronym>HTTP</acronym> and the
  11. Atom syndication formation. The <classname>Zend_Gdata</classname> component is a
  12. <acronym>PHP</acronym> 5 interface for accessing Google Data from <acronym>PHP</acronym>.
  13. The <classname>Zend_Gdata</classname> component also supports accessing other services
  14. implementing the Atom Publishing Protocol.
  15. </para>
  16. <para>
  17. See
  18. <ulink url="http://code.google.com/apis/gdata/">http://code.google.com/apis/gdata/</ulink>
  19. for more information about Google Data <acronym>API</acronym>.
  20. </para>
  21. <para>
  22. The services that are accessible by <classname>Zend_Gdata</classname> include the
  23. following:
  24. <itemizedlist>
  25. <listitem>
  26. <para>
  27. <link linkend="zend.gdata.calendar">Google Calendar</link>
  28. is a popular online calendar application.
  29. </para>
  30. </listitem>
  31. <listitem>
  32. <para>
  33. <link linkend="zend.gdata.spreadsheets">Google Spreadsheets</link>
  34. provides an online collaborative spreadsheets tool which
  35. can be used as a simple data store for your applications.
  36. </para>
  37. </listitem>
  38. <listitem>
  39. <para>
  40. <link linkend="zend.gdata.docs">Google Documents List</link>
  41. provides an online list of all spreadsheets, word processing documents,
  42. and presentations stored in a Google account.
  43. </para>
  44. </listitem>
  45. <listitem>
  46. <para>
  47. <link linkend="zend.gdata.gapps">Google Provisioning</link>
  48. provides the ability to create, retrieve, update, and
  49. delete user accounts, nicknames, groups, and email lists on a
  50. Google Apps hosted domain.
  51. </para>
  52. </listitem>
  53. <listitem>
  54. <para>
  55. <link linkend="zend.gdata.gbase">Google Base</link>
  56. provides the ability to retrieve, post, update, and
  57. delete items in Google Base.
  58. </para>
  59. </listitem>
  60. <listitem>
  61. <para>
  62. <link linkend="zend.gdata.youtube">YouTube</link>
  63. provides the ability to search and retrieve videos,
  64. comments, favorites, subscriptions, user profiles
  65. and more.
  66. </para>
  67. </listitem>
  68. <listitem>
  69. <para>
  70. <link linkend="zend.gdata.photos">Picasa Web Albums</link>
  71. provides an online photo sharing application.
  72. </para>
  73. </listitem>
  74. <listitem>
  75. <para>
  76. <link linkend="zend.gdata.analytics">Google Analytics</link>
  77. is a visitor statistics application.
  78. </para>
  79. </listitem>
  80. <listitem>
  81. <para>
  82. <ulink
  83. url="http://code.google.com/apis/blogger/developers_guide_php.html">Google
  84. Blogger</ulink> is a popular Internet provider of
  85. "push-button publishing" and syndication.
  86. </para>
  87. </listitem>
  88. <listitem>
  89. <para>
  90. Google CodeSearch
  91. allows you to search public source code from many projects.
  92. </para>
  93. </listitem>
  94. <listitem>
  95. <para>
  96. Google Notebook
  97. allows you to view public Notebook content.
  98. </para>
  99. </listitem>
  100. </itemizedlist>
  101. </para>
  102. <note>
  103. <title>Unsupported services</title>
  104. <para>
  105. <classname>Zend_Gdata</classname> does not provide an interface to any other Google
  106. service, such as Search, Gmail, Translation, or Maps.
  107. Only services that support the Google Data <acronym>API</acronym> are supported.
  108. </para>
  109. </note>
  110. <sect2 id="zend.gdata.introduction.structure">
  111. <title>Structure of Zend_Gdata</title>
  112. <para>
  113. <classname>Zend_Gata</classname> is composed of several types of classes:
  114. <itemizedlist>
  115. <listitem>
  116. <para>
  117. Service classes - inheriting from <classname>Zend_Gdata_App</classname>.
  118. These also include other classes such as <classname>Zend_Gdata</classname>,
  119. <classname>Zend_Gdata_Spreadsheets</classname>, etc. These classes enable
  120. interacting with APP or GData services and provide the
  121. ability to retrieve feeds, retrieve entries, post
  122. entries, update entries and delete entries.
  123. </para>
  124. </listitem>
  125. <listitem>
  126. <para>
  127. Query classes - inheriting from <classname>Zend_Gdata_Query</classname>.
  128. These also include other classes for specific services,
  129. such as <classname>Zend_Gdata_Spreadsheets_ListQuery</classname> and
  130. <classname>Zend_Gdata_Spreadsheets_CellQuery</classname>. Query classes
  131. provide methods used to construct a query for data
  132. to be retrieved from GData services. Methods include
  133. getters and setters like <methodname>setUpdatedMin()</methodname>,
  134. <methodname>setStartIndex()</methodname>, and
  135. <methodname>getPublishedMin()</methodname>. The query classes also
  136. have a method to generate a <acronym>URL</acronym> representing the
  137. constructed query -- <methodname>getQueryUrl()</methodname>.
  138. Alternatively, the query string component of the <acronym>URL</acronym>
  139. can be retrieved used the <methodname>getQueryString()</methodname>
  140. method.
  141. </para>
  142. </listitem>
  143. <listitem>
  144. <para>
  145. Feed classes - inheriting from <classname>Zend_Gdata_App_Feed</classname>.
  146. These also include other classes such as
  147. <classname>Zend_Gdata_Feed</classname>,
  148. <classname>Zend_Gdata_Spreadsheets_SpreadsheetFeed</classname>,
  149. and <classname>Zend_Gdata_Spreadsheets_ListFeed</classname>.
  150. These classes represent feeds of entries retrieved
  151. from services. They are primarily used to retrieve
  152. data returned from services.
  153. </para>
  154. </listitem>
  155. <listitem>
  156. <para>
  157. Entry classes - inheriting from <classname>Zend_Gdata_App_Entry</classname>.
  158. These also include other classes such as
  159. <classname>Zend_Gdata_Entry</classname>, and
  160. <classname>Zend_Gdata_Spreadsheets_ListEntry</classname>.
  161. These classes represent entries retrieved from
  162. services or used for constructing data to send to
  163. services. In addition to being able to set the
  164. properties of an entry (such as the spreadsheet cell
  165. value), you can use an entry object to send update
  166. or delete requests to a service. For example,
  167. you can call <command>$entry->save()</command> to save
  168. changes made to an entry back to service from which
  169. the entry initiated, or <command>$entry->delete()</command>
  170. to delete an entry from the server.
  171. </para>
  172. </listitem>
  173. <listitem>
  174. <para>
  175. Other Data model classes - inheriting from
  176. <classname>Zend_Gdata_App_Extension</classname>. These include classes such
  177. as <classname>Zend_Gdata_App_Extension_Title</classname> (representing the
  178. atom:title <acronym>XML</acronym> element),
  179. <classname>Zend_Gdata_Extension_When</classname>
  180. (representing the gd:when <acronym>XML</acronym> element used by the
  181. GData Event "Kind"), and
  182. <classname>Zend_Gdata_Extension_Cell</classname> (representing the gs:cell
  183. <acronym>XML</acronym> element used by Google Spreadsheets). These
  184. classes are used purely to store the data retrieved
  185. back from services and for constructing data to be
  186. sent to services. These include getters and setters
  187. such as
  188. <methodname>setText()</methodname> to set the child text
  189. node of an element, <methodname>getText()</methodname> to retrieve
  190. the text node of an element, <methodname>getStartTime()</methodname>
  191. to retrieve the start time attribute of a When element,
  192. and other similiar methods.
  193. The data model classes also include methods such as
  194. <methodname>getDOM()</methodname> to retrieve a DOM representation
  195. of the element and all children and
  196. <methodname>transferFromDOM()</methodname> to construct a data
  197. model representation of a DOM tree.
  198. </para>
  199. </listitem>
  200. </itemizedlist>
  201. </para>
  202. </sect2>
  203. <sect2 id="zend.gdata.introduction.services">
  204. <title>Interacting with Google Services</title>
  205. <para>
  206. Google data services are based upon the Atom Publishing Protocol
  207. (APP) and the Atom syndication format. To interact with APP or
  208. Google services using the <classname>Zend_Gdata</classname> component, you need to use
  209. the service classes such as <classname>Zend_Gdata_App</classname>,
  210. <classname>Zend_Gdata</classname>, <classname>Zend_Gdata_Spreadsheets</classname>, etc.
  211. These service classes provide methods to retrieve data from services as feeds, insert
  212. new entries into feeds, update entries, and delete entries.
  213. </para>
  214. <para>
  215. Note: A full example of working with <classname>Zend_Gdata</classname> is available in
  216. the <filename>demos/Zend/Gdata</filename> directory. This example is runnable
  217. from the command-line, but the methods contained within are easily
  218. portable to a web application.
  219. </para>
  220. </sect2>
  221. <sect2 id="zend.gdata.introduction.magicfactory">
  222. <title>Obtaining instances of Zend_Gdata classes</title>
  223. <para>
  224. The Zend Framework naming standards require that all classes be
  225. named based upon the directory structure in which they are located.
  226. For instance, extensions related to Spreadsheets are stored in:
  227. <filename>Zend/Gdata/Spreadsheets/Extension/...</filename> and, as a result
  228. of this, are named
  229. <classname>Zend_Gdata_Spreadsheets_Extension_...</classname>.
  230. This causes a lot of typing if you're trying to construct a new
  231. instance of a spreadsheet cell element!
  232. </para>
  233. <para>
  234. We've implemented a magic factory method in all service classes
  235. (such as <classname>Zend_Gdata_App</classname>, <classname>Zend_Gdata</classname>,
  236. <classname>Zend_Gdata_Spreadsheets</classname>) that should make constructing new
  237. instances of data model, query and other classes much easier. This magic factory is
  238. implemented by using the magic <methodname>__call()</methodname> method to intercept all
  239. attempts to call <command>$service->newXXX(arg1, arg2, ...)</command>. Based off
  240. the value of XXX, a search is performed in all registered 'packages'
  241. for the desired class. Here's some examples:
  242. </para>
  243. <programlisting language="php"><![CDATA[
  244. $ss = new Zend_Gdata_Spreadsheets();
  245. // creates a Zend_Gdata_App_Spreadsheets_CellEntry
  246. $entry = $ss->newCellEntry();
  247. // creates a Zend_Gdata_App_Spreadsheets_Extension_Cell
  248. $cell = $ss->newCell();
  249. $cell->setText('My cell value');
  250. $cell->setRow('1');
  251. $cell->setColumn('3');
  252. $entry->cell = $cell;
  253. // ... $entry can then be used to send an update to a Google Spreadsheet
  254. ]]></programlisting>
  255. <para>
  256. Each service class in the inheritance tree is responsible for
  257. registering the appropriate 'packages' (directories) which are to
  258. be searched when calling the magic factory method.
  259. </para>
  260. </sect2>
  261. <sect2 id="zend.gdata.introduction.authentication">
  262. <title>Google Data Client Authentication</title>
  263. <para>
  264. Most Google Data services require client applications to
  265. authenticate against the Google server before accessing
  266. private data, or saving or deleting data.
  267. There are two implementations of authentication for Google Data:
  268. <link linkend="zend.gdata.authsub">AuthSub</link> and
  269. <link linkend="zend.gdata.clientlogin">ClientLogin</link>.
  270. <classname>Zend_Gdata</classname> offers class interfaces for both of these methods.
  271. </para>
  272. <para>
  273. Most other types of queries against Google Data services do not
  274. require authentication.
  275. </para>
  276. </sect2>
  277. <sect2 id="zend.gdata.introduction.dependencies">
  278. <title>Dependencies</title>
  279. <para>
  280. <classname>Zend_Gdata</classname> makes use of
  281. <link linkend="zend.http.client">Zend_Http_Client</link> to send
  282. requests to google.com and fetch results. The response to most
  283. Google Data requests is returned as a subclass of the
  284. <classname>Zend_Gdata_App_Feed</classname> or
  285. <classname>Zend_Gdata_App_Entry</classname> classes.
  286. </para>
  287. <para>
  288. <classname>Zend_Gdata</classname> assumes your <acronym>PHP</acronym> application is
  289. running on a host that has a direct connection to the Internet.
  290. The <classname>Zend_Gdata</classname> client operates by contacting Google Data servers.
  291. </para>
  292. </sect2>
  293. <sect2 id="zend.gdata.introduction.creation">
  294. <title>Creating a new Gdata client</title>
  295. <para>
  296. Create a new object of class <classname>Zend_Gdata_App</classname>,
  297. <classname>Zend_Gdata</classname>, or one of the subclasses available that offer helper
  298. methods for service-specific behavior.
  299. </para>
  300. <para>
  301. The single optional parameter to the <classname>Zend_Gdata_App</classname> constructor
  302. is an instance of
  303. <link linkend="zend.http.client">Zend_Http_Client</link>.
  304. If you don't pass this parameter, <classname>Zend_Gdata</classname> creates a default
  305. <classname>Zend_Http_Client</classname> object, which will not have associated
  306. credentials to access private feeds. Specifying the
  307. <classname>Zend_Http_Client</classname> object also allows you to
  308. pass configuration options to that client object.
  309. </para>
  310. <programlisting language="php"><![CDATA[
  311. $client = new Zend_Http_Client();
  312. $client->setConfig( ...options... );
  313. $gdata = new Zend_Gdata($client);
  314. ]]></programlisting>
  315. <para>
  316. Beginning with Zend Framework 1.7, support has been added for
  317. protocol versioning. This allows the client and server to support
  318. new features while maintaining backwards compatibility. While most
  319. services will manage this for you, if you create a <classname>Zend_Gdata</classname>
  320. instance directly (as opposed to one of its subclasses), you may
  321. need to specify the desired protocol version to access certain
  322. server functionality.
  323. </para>
  324. <programlisting language="php"><![CDATA[
  325. $client = new Zend_Http_Client();
  326. $client->setConfig( ...options... );
  327. $gdata = new Zend_Gdata($client);
  328. $gdata->setMajorProtocolVersion(2);
  329. $gdata->setMinorProtocolVersion(null);
  330. ]]></programlisting>
  331. <para>
  332. Also see the sections on authentication for methods to
  333. create an authenticated <classname>Zend_Http_Client</classname> object.
  334. </para>
  335. </sect2>
  336. <sect2 id="zend.gdata.introduction.parameters">
  337. <title>Common Query Parameters</title>
  338. <para>
  339. You can specify parameters to customize queries with <classname>Zend_Gdata</classname>.
  340. Query parameters are specified using subclasses of
  341. <classname>Zend_Gdata_Query</classname>. The <classname>Zend_Gdata_Query</classname>
  342. class includes methods to set all query parameters used throughout GData services.
  343. Individual services, such as Spreadsheets, also provide query classes to defined
  344. parameters which are custom to the particular service and feeds.
  345. Spreadsheets includes a CellQuery class to query the Cell Feed
  346. and a ListQuery class to query the List Feed, as different
  347. query parameters are applicable to each of those feed types.
  348. The GData-wide parameters are described below.
  349. </para>
  350. <itemizedlist>
  351. <listitem>
  352. <para>
  353. The <property>q</property> parameter specifies a full-text
  354. query. The value of the parameter is a string.
  355. </para>
  356. <para>
  357. Set this parameter with the <methodname>setQuery()</methodname>
  358. function.
  359. </para>
  360. </listitem>
  361. <listitem>
  362. <para>
  363. The <property>alt</property> parameter specifies the feed type.
  364. The value of the parameter can be <property>atom</property>,
  365. <property>rss</property>, <property>json</property>,
  366. or <property>json-in-script</property>.
  367. If you don't specify this parameter, the default feed type
  368. is <property>atom</property>. NOTE: Only the output of the
  369. atom feed format can be processed using
  370. <classname>Zend_Gdata</classname>.
  371. The <classname>Zend_Http_Client</classname> could be used to retrieve
  372. feeds in other formats, using query <acronym>URL</acronym>s generated by the
  373. <classname>Zend_Gdata_Query</classname> class and its subclasses.
  374. </para>
  375. <para>
  376. Set this parameter with the <methodname>setAlt()</methodname>
  377. function.
  378. </para>
  379. </listitem>
  380. <listitem>
  381. <para>
  382. The <property>maxResults</property> parameter limits the number
  383. of entries in the feed. The value of the parameter is
  384. an integer. The number of entries returned in the feed
  385. will not exceed this value.
  386. </para>
  387. <para>
  388. Set this parameter with the <methodname>setMaxResults()</methodname> function.
  389. </para>
  390. </listitem>
  391. <listitem>
  392. <para>
  393. The <property>startIndex</property> parameter specifies the
  394. ordinal number of the first entry returned in the feed.
  395. Entries before this number are skipped.
  396. </para>
  397. <para>
  398. Set this parameter with the <methodname>setStartIndex()</methodname>
  399. function.
  400. </para>
  401. </listitem>
  402. <listitem>
  403. <para>
  404. The <property>updatedMin</property> and <property>updatedMax</property>
  405. parameters specify bounds on the entry date.
  406. If you specify a value for <property>updatedMin</property>,
  407. no entries that were updated earlier than the date
  408. you specify are included in the feed. Likewise
  409. no entries updated after the date specified by
  410. <property>updatedMax</property> are included.
  411. </para>
  412. <para>
  413. You can use numeric timestamps, or a variety of
  414. date/time string representations as the value for
  415. these parameters.
  416. </para>
  417. <para>
  418. Set this parameter with the <methodname>setUpdatedMin()</methodname>
  419. and <methodname>setUpdatedMax()</methodname> functions.
  420. </para>
  421. </listitem>
  422. </itemizedlist>
  423. <para>
  424. There is a <methodname>get*()</methodname> function for each
  425. <methodname>set*()</methodname> function.
  426. </para>
  427. <programlisting language="php"><![CDATA[
  428. $query = new Zend_Gdata_Query();
  429. $query->setMaxResults(10);
  430. echo $query->getMaxResults(); // returns 10
  431. ]]></programlisting>
  432. <para>
  433. The <classname>Zend_Gdata</classname> class also implements "magic" getter and
  434. setter methods, so you can use the name of the parameter
  435. as a virtual member of the class.
  436. </para>
  437. <programlisting language="php"><![CDATA[
  438. $query = new Zend_Gdata_Query();
  439. $query->maxResults = 10;
  440. echo $query->maxResults; // returns 10
  441. ]]></programlisting>
  442. <para>
  443. You can clear all parameters with the <methodname>resetParameters()</methodname>
  444. function. This is useful to do if you reuse a <classname>Zend_Gdata</classname>
  445. object for multiple queries.
  446. </para>
  447. <programlisting language="php"><![CDATA[
  448. $query = new Zend_Gdata_Query();
  449. $query->maxResults = 10;
  450. // ...get feed...
  451. $query->resetParameters(); // clears all parameters
  452. // ...get a different feed...
  453. ]]></programlisting>
  454. </sect2>
  455. <sect2 id="zend.gdata.introduction.getfeed">
  456. <title>Fetching a Feed</title>
  457. <para>
  458. Use the <methodname>getFeed()</methodname> function to retrieve
  459. a feed from a specified <acronym>URI</acronym>.
  460. This function returns an instance of class specified
  461. as the second argument to getFeed, which defaults to
  462. <classname>Zend_Gdata_Feed</classname>.
  463. </para>
  464. <programlisting language="php"><![CDATA[
  465. $gdata = new Zend_Gdata();
  466. $query = new Zend_Gdata_Query(
  467. 'http://www.blogger.com/feeds/blogID/posts/default');
  468. $query->setMaxResults(10);
  469. $feed = $gdata->getFeed($query);
  470. ]]></programlisting>
  471. <para>
  472. See later sections for special functions in each
  473. helper class for Google Data services. These
  474. functions help you to get feeds from the <acronym>URI</acronym> that is
  475. appropriate for the respective service.
  476. </para>
  477. </sect2>
  478. <sect2 id="zend.gdata.introduction.paging">
  479. <title>Working with Multi-page Feeds</title>
  480. <para>
  481. When retrieving a feed that contains a large number of entries,
  482. the feed may be broken up into many smaller "pages" of feeds. When
  483. this occurs, each page will contain a link to the next page in the
  484. series. This link can be accessed by calling
  485. <methodname>getLink('next')</methodname>. The following example shows how to
  486. retrieve the next page of a feed:
  487. </para>
  488. <programlisting language="php"><![CDATA[
  489. function getNextPage($feed) {
  490. $nextURL = $feed->getLink('next');
  491. if ($nextURL !== null) {
  492. return $gdata->getFeed($nextURL);
  493. } else {
  494. return null;
  495. }
  496. }
  497. ]]></programlisting>
  498. <para>
  499. If you would prefer not to work with pages in your application,
  500. pass the first page of the feed into
  501. <methodname>Zend_Gdata_App::retrieveAllEntriesForFeed()</methodname>, which
  502. will consolidate all entries from each page into a single feed.
  503. This example shows how to use this function:
  504. </para>
  505. <programlisting language="php"><![CDATA[
  506. $gdata = new Zend_Gdata();
  507. $query = new Zend_Gdata_Query(
  508. 'http://www.blogger.com/feeds/blogID/posts/default');
  509. $feed = $gdata->retrieveAllEntriesForFeed($gdata->getFeed($query));
  510. ]]></programlisting>
  511. <para>
  512. Keep in mind when calling this function that it may take a long
  513. time to complete on large feeds. You may need to increase <acronym>PHP</acronym>'s
  514. execution time limit by calling <methodname>set_time_limit()</methodname>.
  515. </para>
  516. </sect2>
  517. <sect2 id="zend.gdata.introduction.usefeedentry">
  518. <title>Working with Data in Feeds and Entries</title>
  519. <para>
  520. After retrieving a feed, you can read the data from the feed
  521. or the entries contained in the feed using either the accessors
  522. defined in each of the data model classes or the magic
  523. accessors. Here's an example:
  524. </para>
  525. <programlisting language="php"><![CDATA[
  526. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  527. $gdata = new Zend_Gdata($client);
  528. $query = new Zend_Gdata_Query(
  529. 'http://www.blogger.com/feeds/blogID/posts/default');
  530. $query->setMaxResults(10);
  531. $feed = $gdata->getFeed($query);
  532. foreach ($feed as $entry) {
  533. // using the magic accessor
  534. echo 'Title: ' . $entry->title->text;
  535. // using the defined accessors
  536. echo 'Content: ' . $entry->getContent()->getText();
  537. }
  538. ]]></programlisting>
  539. </sect2>
  540. <sect2 id="zend.gdata.introduction.updateentry">
  541. <title>Updating Entries</title>
  542. <para>
  543. After retrieving an entry, you can update that entry and save
  544. changes back to the server. Here's an example:
  545. </para>
  546. <programlisting language="php"><![CDATA[
  547. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  548. $gdata = new Zend_Gdata($client);
  549. $query = new Zend_Gdata_Query(
  550. 'http://www.blogger.com/feeds/blogID/posts/default');
  551. $query->setMaxResults(10);
  552. $feed = $gdata->getFeed($query);
  553. foreach ($feed as $entry) {
  554. // update the title to append 'NEW'
  555. echo 'Old Title: ' . $entry->title->text;
  556. $entry->title->text = $entry->title->text . ' NEW';
  557. // update the entry on the server
  558. $newEntry = $entry->save();
  559. echo 'New Title: ' . $newEntry->title->text;
  560. }
  561. ]]></programlisting>
  562. </sect2>
  563. <sect2 id="zend.gdata.introduction.post">
  564. <title>Posting Entries to Google Servers</title>
  565. <para>
  566. The <classname>Zend_Gdata</classname> object has a function
  567. <methodname>insertEntry()</methodname> with which you can upload data to save
  568. new entries to Google Data services.
  569. </para>
  570. <para>
  571. You can use the data model classes for each service to construct
  572. the appropriate entry to post to Google's services. The
  573. <methodname>insertEntry()</methodname> function will accept a child of
  574. <classname>Zend_Gdata_App_Entry</classname> as data to post to the service.
  575. The method returns a child of <classname>Zend_Gdata_App_Entry</classname>
  576. which represents the state of the entry as it was returned from
  577. the server.
  578. </para>
  579. <para>
  580. Alternatively, you could construct the <acronym>XML</acronym> structure for an entry
  581. as a string and pass the string to the <methodname>insertEntry()</methodname>
  582. function.
  583. </para>
  584. <programlisting language="php"><![CDATA[
  585. $gdata = new Zend_Gdata($authenticatedHttpClient);
  586. $entry = $gdata->newEntry();
  587. $entry->title = $gdata->newTitle('Playing football at the park');
  588. $content =
  589. $gdata->newContent('We will visit the park and play football');
  590. $content->setType('text');
  591. $entry->content = $content;
  592. $entryResult = $gdata->insertEntry($entry,
  593. 'http://www.blogger.com/feeds/blogID/posts/default');
  594. echo 'The <id> of the resulting entry is: ' . $entryResult->id->text;
  595. ]]></programlisting>
  596. <para>
  597. To post entries, you must be using an authenticated
  598. <classname>Zend_Http_Client</classname> that you created using the
  599. <classname>Zend_Gdata_AuthSub</classname> or
  600. <classname>Zend_Gdata_ClientLogin</classname> classes.
  601. </para>
  602. </sect2>
  603. <sect2 id="zend.gdata.introduction.delete">
  604. <title>Deleting Entries on Google Servers</title>
  605. <para>
  606. Option 1: The <classname>Zend_Gdata</classname> object has a function
  607. <methodname>delete()</methodname> with which you can delete entries from Google Data
  608. services. Pass the edit <acronym>URL</acronym> value from
  609. a feed entry to the <methodname>delete()</methodname> method.
  610. </para>
  611. <para>
  612. Option 2: Alternatively, you can call <command>$entry->delete()</command>
  613. on an entry retrieved from a Google service.
  614. </para>
  615. <programlisting language="php"><![CDATA[
  616. $gdata = new Zend_Gdata($authenticatedHttpClient);
  617. // a Google Data feed
  618. $feedUri = ...;
  619. $feed = $gdata->getFeed($feedUri);
  620. foreach ($feed as $feedEntry) {
  621. // Option 1 - delete the entry directly
  622. $feedEntry->delete();
  623. // Option 2 - delete the entry by passing the edit URL to
  624. // $gdata->delete()
  625. // $gdata->delete($feedEntry->getEditLink()->href);
  626. }
  627. ]]></programlisting>
  628. <para>
  629. To delete entries, you must be using an authenticated
  630. <classname>Zend_Http_Client</classname> that you created using the
  631. <classname>Zend_Gdata_AuthSub</classname> or
  632. <classname>Zend_Gdata_ClientLogin</classname> classes.
  633. </para>
  634. </sect2>
  635. </sect1>