Zend_Gdata-Introduction.xml 30 KB

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