Zend_Gdata-Introduction.xml 31 KB

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