2
0

Zend_Gdata_Docs.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 <acronym>API</acronym> allows client applications to
  7. upload documents to Google Documents and list them in the form of
  8. Google Data <acronym>API</acronym> ("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 <ulink
  14. 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 <acronym>API</acronym>.
  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 <methodname>getDocumentListFeed()</methodname> 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. (<command>$feed->entries</command>), 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 separated 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 <acronym>API</acronym> 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
  108. Data <acronym>API</acronym> Reference Guide</ulink>.
  109. </para>
  110. <sect3 id="zend.gdata.docs.listwpdocuments">
  111. <title>Get a List of Word Processing Documents</title>
  112. <para>
  113. You can also request a feed containing all of your documents of a specific type. For
  114. example, to see a list of your work processing documents, you would perform a
  115. category query as follows.
  116. </para>
  117. <programlisting language="php"><![CDATA[
  118. $feed = $docs->getDocumentListFeed(
  119. 'http://docs.google.com/feeds/documents/private/full/-/document');
  120. ]]></programlisting>
  121. </sect3>
  122. <sect3 id="zend.gdata.docs.listspreadsheets">
  123. <title>Get a List of Spreadsheets</title>
  124. <para>
  125. To request a list of your Google Spreadsheets, use the following category query:
  126. </para>
  127. <programlisting language="php"><![CDATA[
  128. $feed = $docs->getDocumentListFeed(
  129. 'http://docs.google.com/feeds/documents/private/full/-/spreadsheet');
  130. ]]></programlisting>
  131. </sect3>
  132. <sect3 id="zend.gdata.docs.textquery">
  133. <title>Performing a text query</title>
  134. <para>
  135. You can search the content of documents by using a
  136. <classname>Zend_Gdata_Docs_Query</classname> in your request. A Query object
  137. can be used to construct the query <acronym>URI</acronym>, with the search term
  138. being passed in as a parameter. Here is an example method which queries
  139. the documents list for documents which contain the search string:
  140. </para>
  141. <programlisting language="php"><![CDATA[
  142. $docsQuery = new Zend_Gdata_Docs_Query();
  143. $docsQuery->setQuery($query);
  144. $feed = $client->getDocumentListFeed($docsQuery);
  145. ]]></programlisting>
  146. </sect3>
  147. </sect2>
  148. </sect1>