Zend_Gdata-Introduction.xml 30 KB

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