2
0

Zend_Gdata_Docs.xml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.gdata.docs">
  4. <title>Using Google Documents List Data API</title>
  5. <para>
  6. The Google Documents List Data API allows client applications to
  7. upload documents to Google Documents and list them in the form of
  8. Google Data API ("GData") feeds. Your client application can request
  9. a list of a user's documents, and query the content in an existing
  10. document.
  11. </para>
  12. <para>
  13. See
  14. <ulink url="http://code.google.com/apis/documents/overview.html">http://code.google.com/apis/documents/overview.html</ulink>
  15. for more information about the Google Documents List API.
  16. </para>
  17. <sect2 id="zend.gdata.docs.listdocuments">
  18. <title>Get a List of Documents</title>
  19. <para>
  20. You can get a list of the Google Documents for a particular user by using
  21. the <code>getDocumentListFeed</code> method of the docs
  22. service. The service will return a
  23. <classname>Zend_Gdata_Docs_DocumentListFeed</classname> object
  24. containing a list of documents associated with the authenticated
  25. user.
  26. </para>
  27. <programlisting language="php"><![CDATA[
  28. $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
  29. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  30. $docs = new Zend_Gdata_Docs($client);
  31. $feed = $docs->getDocumentListFeed();
  32. ]]></programlisting>
  33. <para>
  34. The resulting <classname>Zend_Gdata_Docs_DocumentListFeed</classname> object
  35. represents the response from the server. This feed contains a list of
  36. <classname>Zend_Gdata_Docs_DocumentListEntry</classname> objects
  37. (<code>$feed->entries</code>), each of which represents a single
  38. Google Document.
  39. </para>
  40. </sect2>
  41. <sect2 id="zend.gdata.docs.creating">
  42. <title>Upload a Document</title>
  43. <para>
  44. You can create a new Google Document by uploading a word
  45. processing document, spreadsheet, or presentation. This example
  46. is from the interactive Docs.php sample which comes with the
  47. library. It demonstrates uploading a file and printing
  48. information about the result from the server.
  49. </para>
  50. <programlisting language="php"><![CDATA[
  51. /**
  52. * Upload the specified document
  53. *
  54. * @param Zend_Gdata_Docs $docs The service object to use for communicating
  55. * with the Google Documents server.
  56. * @param boolean $html True if output should be formatted for display in a
  57. * web browser.
  58. * @param string $originalFileName The name of the file to be uploaded. The
  59. * MIME type of the file is determined from the extension on this file
  60. * name. For example, test.csv is uploaded as a comma seperated volume
  61. * and converted into a spreadsheet.
  62. * @param string $temporaryFileLocation (optional) The file in which the
  63. * data for the document is stored. This is used when the file has been
  64. * uploaded from the client's machine to the server and is stored in
  65. * a temporary file which does not have an extension. If this parameter
  66. * is null, the file is read from the originalFileName.
  67. */
  68. function uploadDocument($docs, $html, $originalFileName,
  69. $temporaryFileLocation) {
  70. $fileToUpload = $originalFileName;
  71. if ($temporaryFileLocation) {
  72. $fileToUpload = $temporaryFileLocation;
  73. }
  74. // Upload the file and convert it into a Google Document. The original
  75. // file name is used as the title of the document and the MIME type
  76. // is determined based on the extension on the original file name.
  77. $newDocumentEntry = $docs->uploadFile($fileToUpload, $originalFileName,
  78. null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);
  79. echo "New Document Title: ";
  80. if ($html) {
  81. // Find the URL of the HTML view of this document.
  82. $alternateLink = '';
  83. foreach ($newDocumentEntry->link as $link) {
  84. if ($link->getRel() === 'alternate') {
  85. $alternateLink = $link->getHref();
  86. }
  87. }
  88. // Make the title link to the document on docs.google.com.
  89. echo "<a href=\"$alternateLink\">\n";
  90. }
  91. echo $newDocumentEntry->title."\n";
  92. if ($html) {echo "</a>\n";}
  93. }
  94. ]]></programlisting>
  95. </sect2>
  96. <sect2 id="zend.gdata.docs.queries">
  97. <title>Searching the documents feed</title>
  98. <para>
  99. You can search the Document List using some of the <ulink
  100. url="http://code.google.com/apis/gdata/reference.html#Queries">standard
  101. Google Data API query parameters</ulink>. Categories are used to
  102. restrict the
  103. type of document (word processor document, spreadsheet) returned.
  104. The full-text query string is used to search the content of all
  105. the documents. More detailed information on parameters specific
  106. to the Documents List can be found in the <ulink
  107. url="http://code.google.com/apis/documents/reference.html#Parameters">Documents List Data API Reference Guide</ulink>.
  108. </para>
  109. <sect3 id="zend.gdata.docs.listwpdocuments">
  110. <title>Get a List of Word Processing Documents</title>
  111. <para>
  112. You can also request a feed containing all of your documents of a specific type. For example, to see a list of your work processing documents, you would perform a category query as follows.
  113. </para>
  114. <programlisting language="php"><![CDATA[
  115. $feed = $docs->getDocumentListFeed(
  116. 'http://docs.google.com/feeds/documents/private/full/-/document');
  117. ]]></programlisting>
  118. </sect3>
  119. <sect3 id="zend.gdata.docs.listspreadsheets">
  120. <title>Get a List of Spreadsheets</title>
  121. <para>
  122. To request a list of your Google Spreadsheets, use the following category query:
  123. </para>
  124. <programlisting language="php"><![CDATA[
  125. $feed = $docs->getDocumentListFeed(
  126. 'http://docs.google.com/feeds/documents/private/full/-/spreadsheet');
  127. ]]></programlisting>
  128. </sect3>
  129. <sect3 id="zend.gdata.docs.textquery">
  130. <title>Performing a text query</title>
  131. <para>
  132. You can search the content of documents by using a
  133. <classname>Zend_Gdata_Docs_Query</classname> in your request. A Query object
  134. can be used to construct the query URI, with the search term being
  135. passed in as a parameter. Here is an example method which queries
  136. the documents list for documents which contain the search string:
  137. </para>
  138. <programlisting language="php"><![CDATA[
  139. $docsQuery = new Zend_Gdata_Docs_Query();
  140. $docsQuery->setQuery($query);
  141. $feed = $client->getDocumentListFeed($docsQuery);
  142. ]]></programlisting>
  143. </sect3>
  144. </sect2>
  145. </sect1>