Zend_Gdata-Introduction.xml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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.youtube">YouTube</link>
  56. provides the ability to search and retrieve videos,
  57. comments, favorites, subscriptions, user profiles
  58. and more.
  59. </para>
  60. </listitem>
  61. <listitem>
  62. <para>
  63. <link linkend="zend.gdata.photos">Picasa Web Albums</link>
  64. provides an online photo sharing application.
  65. </para>
  66. </listitem>
  67. <listitem>
  68. <para>
  69. <link linkend="zend.gdata.analytics">Google Analytics</link>
  70. is a visitor statistics application.
  71. </para>
  72. </listitem>
  73. <listitem>
  74. <para>
  75. <ulink
  76. url="http://code.google.com/apis/blogger/developers_guide_php.html">Google
  77. Blogger</ulink> 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 -- <methodname>getQueryUrl()</methodname>.
  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
  153. <classname>Zend_Gdata_Spreadsheets_ListEntry</classname>.
  154. These classes represent entries retrieved from
  155. services or used for constructing data to send to
  156. services. In addition to being able to set the
  157. properties of an entry (such as the spreadsheet cell
  158. value), you can use an entry object to send update
  159. or delete requests to a service. For example,
  160. you can call <command>$entry->save()</command> to save
  161. changes made to an entry back to service from which
  162. the entry initiated, or <command>$entry->delete()</command>
  163. to delete an entry from the server.
  164. </para>
  165. </listitem>
  166. <listitem>
  167. <para>
  168. Other Data model classes - inheriting from
  169. <classname>Zend_Gdata_App_Extension</classname>. These include classes such
  170. as <classname>Zend_Gdata_App_Extension_Title</classname> (representing the
  171. atom:title <acronym>XML</acronym> element),
  172. <classname>Zend_Gdata_Extension_When</classname>
  173. (representing the gd:when <acronym>XML</acronym> element used by the
  174. GData Event "Kind"), and
  175. <classname>Zend_Gdata_Extension_Cell</classname> (representing the gs:cell
  176. <acronym>XML</acronym> element used by Google Spreadsheets). These
  177. classes are used purely to store the data retrieved
  178. back from services and for constructing data to be
  179. sent to services. These include getters and setters
  180. such as
  181. <methodname>setText()</methodname> to set the child text
  182. node of an element, <methodname>getText()</methodname> to retrieve
  183. the text node of an element, <methodname>getStartTime()</methodname>
  184. to retrieve the start time attribute of a When element,
  185. and other similiar methods.
  186. The data model classes also include methods such as
  187. <methodname>getDOM()</methodname> to retrieve a DOM representation
  188. of the element and all children and
  189. <methodname>transferFromDOM()</methodname> to construct a data
  190. model representation of a DOM tree.
  191. </para>
  192. </listitem>
  193. </itemizedlist>
  194. </para>
  195. </sect2>
  196. <sect2 id="zend.gdata.introduction.services">
  197. <title>Interacting with Google Services</title>
  198. <para>
  199. Google data services are based upon the Atom Publishing Protocol
  200. (APP) and the Atom syndication format. To interact with APP or
  201. Google services using the <classname>Zend_Gdata</classname> component, you need to use
  202. the service classes such as <classname>Zend_Gdata_App</classname>,
  203. <classname>Zend_Gdata</classname>, <classname>Zend_Gdata_Spreadsheets</classname>, etc.
  204. These service classes provide methods to retrieve data from services as feeds, insert
  205. new entries into feeds, update entries, and delete entries.
  206. </para>
  207. <para>
  208. Note: A full example of working with <classname>Zend_Gdata</classname> is available in
  209. the <filename>demos/Zend/Gdata</filename> directory. This example is runnable
  210. from the command-line, but the methods contained within are easily
  211. portable to a web application.
  212. </para>
  213. </sect2>
  214. <sect2 id="zend.gdata.introduction.magicfactory">
  215. <title>Obtaining instances of Zend_Gdata classes</title>
  216. <para>
  217. The Zend Framework naming standards require that all classes be
  218. named based upon the directory structure in which they are located.
  219. For instance, extensions related to Spreadsheets are stored in:
  220. <filename>Zend/Gdata/Spreadsheets/Extension/...</filename> and, as a result
  221. of this, are named
  222. <classname>Zend_Gdata_Spreadsheets_Extension_...</classname>.
  223. This causes a lot of typing if you're trying to construct a new
  224. instance of a spreadsheet cell element!
  225. </para>
  226. <para>
  227. We've implemented a magic factory method in all service classes
  228. (such as <classname>Zend_Gdata_App</classname>, <classname>Zend_Gdata</classname>,
  229. <classname>Zend_Gdata_Spreadsheets</classname>) that should make constructing new
  230. instances of data model, query and other classes much easier. This magic factory is
  231. implemented by using the magic <methodname>__call()</methodname> method to intercept all
  232. attempts to call <command>$service->newXXX(arg1, arg2, ...)</command>. Based off
  233. the value of XXX, a search is performed in all registered 'packages'
  234. for the desired class. Here's some examples:
  235. </para>
  236. <programlisting language="php"><![CDATA[
  237. $ss = new Zend_Gdata_Spreadsheets();
  238. // creates a Zend_Gdata_App_Spreadsheets_CellEntry
  239. $entry = $ss->newCellEntry();
  240. // creates a Zend_Gdata_App_Spreadsheets_Extension_Cell
  241. $cell = $ss->newCell();
  242. $cell->setText('My cell value');
  243. $cell->setRow('1');
  244. $cell->setColumn('3');
  245. $entry->cell = $cell;
  246. // ... $entry can then be used to send an update to a Google Spreadsheet
  247. ]]></programlisting>
  248. <para>
  249. Each service class in the inheritance tree is responsible for
  250. registering the appropriate 'packages' (directories) which are to
  251. be searched when calling the magic factory method.
  252. </para>
  253. </sect2>
  254. <sect2 id="zend.gdata.introduction.authentication">
  255. <title>Google Data Client Authentication</title>
  256. <para>
  257. Most Google Data services require client applications to
  258. authenticate against the Google server before accessing
  259. private data, or saving or deleting data.
  260. There are two implementations of authentication for Google Data:
  261. <link linkend="zend.gdata.authsub">AuthSub</link> and
  262. <link linkend="zend.gdata.clientlogin">ClientLogin</link>.
  263. <classname>Zend_Gdata</classname> offers class interfaces for both of these methods.
  264. </para>
  265. <para>
  266. Most other types of queries against Google Data services do not
  267. require authentication.
  268. </para>
  269. </sect2>
  270. <sect2 id="zend.gdata.introduction.dependencies">
  271. <title>Dependencies</title>
  272. <para>
  273. <classname>Zend_Gdata</classname> makes use of
  274. <link linkend="zend.http.client">Zend_Http_Client</link> to send
  275. requests to google.com and fetch results. The response to most
  276. Google Data requests is returned as a subclass of the
  277. <classname>Zend_Gdata_App_Feed</classname> or
  278. <classname>Zend_Gdata_App_Entry</classname> classes.
  279. </para>
  280. <para>
  281. <classname>Zend_Gdata</classname> assumes your <acronym>PHP</acronym> application is
  282. running on a host that has a direct connection to the Internet.
  283. The <classname>Zend_Gdata</classname> client operates by contacting Google Data servers.
  284. </para>
  285. </sect2>
  286. <sect2 id="zend.gdata.introduction.creation">
  287. <title>Creating a new Gdata client</title>
  288. <para>
  289. Create a new object of class <classname>Zend_Gdata_App</classname>,
  290. <classname>Zend_Gdata</classname>, or one of the subclasses available that offer helper
  291. methods for service-specific behavior.
  292. </para>
  293. <para>
  294. The single optional parameter to the <classname>Zend_Gdata_App</classname> constructor
  295. is an instance of
  296. <link linkend="zend.http.client">Zend_Http_Client</link>.
  297. If you don't pass this parameter, <classname>Zend_Gdata</classname> creates a default
  298. <classname>Zend_Http_Client</classname> object, which will not have associated
  299. credentials to access private feeds. Specifying the
  300. <classname>Zend_Http_Client</classname> object also allows you to
  301. pass configuration options to that client object.
  302. </para>
  303. <programlisting language="php"><![CDATA[
  304. $client = new Zend_Http_Client();
  305. $client->setConfig( ...options... );
  306. $gdata = new Zend_Gdata($client);
  307. ]]></programlisting>
  308. <para>
  309. Beginning with Zend Framework 1.7, support has been added for
  310. protocol versioning. This allows the client and server to support
  311. new features while maintaining backwards compatibility. While most
  312. services will manage this for you, if you create a <classname>Zend_Gdata</classname>
  313. instance directly (as opposed to one of its subclasses), you may
  314. need to specify the desired protocol version to access certain
  315. server functionality.
  316. </para>
  317. <programlisting language="php"><![CDATA[
  318. $client = new Zend_Http_Client();
  319. $client->setConfig( ...options... );
  320. $gdata = new Zend_Gdata($client);
  321. $gdata->setMajorProtocolVersion(2);
  322. $gdata->setMinorProtocolVersion(null);
  323. ]]></programlisting>
  324. <para>
  325. Also see the sections on authentication for methods to
  326. create an authenticated <classname>Zend_Http_Client</classname> object.
  327. </para>
  328. </sect2>
  329. <sect2 id="zend.gdata.introduction.parameters">
  330. <title>Common Query Parameters</title>
  331. <para>
  332. You can specify parameters to customize queries with <classname>Zend_Gdata</classname>.
  333. Query parameters are specified using subclasses of
  334. <classname>Zend_Gdata_Query</classname>. The <classname>Zend_Gdata_Query</classname>
  335. class includes methods to set all query parameters used throughout GData services.
  336. Individual services, such as Spreadsheets, also provide query classes to defined
  337. parameters which are custom to the particular service and feeds.
  338. Spreadsheets includes a CellQuery class to query the Cell Feed
  339. and a ListQuery class to query the List Feed, as different
  340. query parameters are applicable to each of those feed types.
  341. The GData-wide parameters are described below.
  342. </para>
  343. <itemizedlist>
  344. <listitem>
  345. <para>
  346. The <property>q</property> parameter specifies a full-text
  347. query. The value of the parameter is a string.
  348. </para>
  349. <para>
  350. Set this parameter with the <methodname>setQuery()</methodname>
  351. function.
  352. </para>
  353. </listitem>
  354. <listitem>
  355. <para>
  356. The <property>alt</property> parameter specifies the feed type.
  357. The value of the parameter can be <property>atom</property>,
  358. <property>rss</property>, <property>json</property>,
  359. or <property>json-in-script</property>.
  360. If you don't specify this parameter, the default feed type
  361. is <property>atom</property>. NOTE: Only the output of the
  362. atom feed format can be processed using
  363. <classname>Zend_Gdata</classname>.
  364. The <classname>Zend_Http_Client</classname> could be used to retrieve
  365. feeds in other formats, using query <acronym>URL</acronym>s generated by the
  366. <classname>Zend_Gdata_Query</classname> class and its subclasses.
  367. </para>
  368. <para>
  369. Set this parameter with the <methodname>setAlt()</methodname>
  370. function.
  371. </para>
  372. </listitem>
  373. <listitem>
  374. <para>
  375. The <property>maxResults</property> parameter limits the number
  376. of entries in the feed. The value of the parameter is
  377. an integer. The number of entries returned in the feed
  378. will not exceed this value.
  379. </para>
  380. <para>
  381. Set this parameter with the <methodname>setMaxResults()</methodname> function.
  382. </para>
  383. </listitem>
  384. <listitem>
  385. <para>
  386. The <property>startIndex</property> 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 <property>updatedMin</property> and <property>updatedMax</property>
  398. parameters specify bounds on the entry date.
  399. If you specify a value for <property>updatedMin</property>,
  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. <property>updatedMax</property> 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 <methodname>get*()</methodname> function for each
  418. <methodname>set*()</methodname> 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
  592. <classname>Zend_Gdata_AuthSub</classname> or
  593. <classname>Zend_Gdata_ClientLogin</classname> classes.
  594. </para>
  595. </sect2>
  596. <sect2 id="zend.gdata.introduction.delete">
  597. <title>Deleting Entries on Google Servers</title>
  598. <para>
  599. Option 1: The <classname>Zend_Gdata</classname> object has a function
  600. <methodname>delete()</methodname> with which you can delete entries from Google Data
  601. services. Pass the edit <acronym>URL</acronym> value from
  602. a feed entry to the <methodname>delete()</methodname> method.
  603. </para>
  604. <para>
  605. Option 2: Alternatively, you can call <command>$entry->delete()</command>
  606. on an entry retrieved from a Google service.
  607. </para>
  608. <programlisting language="php"><![CDATA[
  609. $gdata = new Zend_Gdata($authenticatedHttpClient);
  610. // a Google Data feed
  611. $feedUri = ...;
  612. $feed = $gdata->getFeed($feedUri);
  613. foreach ($feed as $feedEntry) {
  614. // Option 1 - delete the entry directly
  615. $feedEntry->delete();
  616. // Option 2 - delete the entry by passing the edit URL to
  617. // $gdata->delete()
  618. // $gdata->delete($feedEntry->getEditLink()->href);
  619. }
  620. ]]></programlisting>
  621. <para>
  622. To delete entries, you must be using an authenticated
  623. <classname>Zend_Http_Client</classname> that you created using the
  624. <classname>Zend_Gdata_AuthSub</classname> or
  625. <classname>Zend_Gdata_ClientLogin</classname> classes.
  626. </para>
  627. </sect2>
  628. </sect1>