Google Calendar の使用法

Google Documents List Data API の使用法

Google Documents List Data API は、 クライアントアプリケーションから Google Documents にドキュメントをアップロードしたり、 ドキュメントの一覧を Google Data API ("GData") 形式のフィードで取得したりするためのものです。 クライアントアプリケーションからユーザのドキュメントの一覧をリクエストしたり、 ドキュメントの中身を問い合わせたりできます。

Google Documents List API についての詳細は » http://code.google.com/apis/documents/overview.html を参照ください。

ドキュメントの一覧の取得

特定のユーザの Google Documents の一覧を取得するには、docs サービスの getDocumentListFeed メソッドを使用します。 このサービスは Zend_Gdata_Docs_DocumentListFeed オブジェクトを返します。 その中には、認証済みユーザに関連付けられたドキュメントの一覧が含まれます。

  1. $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
  2. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  3. $docs = new Zend_Gdata_Docs($client);
  4. $feed = $docs->getDocumentListFeed();

結果として得られる Zend_Gdata_Docs_DocumentListFeed オブジェクトが、サーバからの応答を表します。 このフィードには Zend_Gdata_Docs_DocumentListEntry オブジェクトの一覧 ($feed->entries) が含まれ、 それぞれがひとつの Google Document を表します。

ドキュメントのアップロード

新しい Google Document を作成するには、 ワープロ文書やスプレッドシート、あるいはプレゼンテーションをアップロードします。 この例はインタラクティブなサンプル Docs.php で、これはライブラリに同梱されています。 これは、ファイルをアップロードした後で、 サーバからその結果の情報を取得して表示するものです。

  1. /**
  2. * Upload the specified document
  3. *
  4. * @param Zend_Gdata_Docs $docs The service object to use for communicating
  5. *     with the Google Documents server.
  6. * @param boolean $html True if output should be formatted for display in a
  7. *     web browser.
  8. * @param string $originalFileName The name of the file to be uploaded. The
  9. *     MIME type of the file is determined from the extension on this file
  10. *     name. For example, test.csv is uploaded as a comma separated volume
  11. *     and converted into a spreadsheet.
  12. * @param string $temporaryFileLocation (optional) The file in which the
  13. *     data for the document is stored. This is used when the file has been
  14. *     uploaded from the client's machine to the server and is stored in
  15. *     a temporary file which does not have an extension. If this parameter
  16. *     is null, the file is read from the originalFileName.
  17. */
  18. function uploadDocument($docs, $html, $originalFileName,
  19.                         $temporaryFileLocation) {
  20.   $fileToUpload = $originalFileName;
  21.   if ($temporaryFileLocation) {
  22.     $fileToUpload = $temporaryFileLocation;
  23.   }
  24.  
  25.   // Upload the file and convert it into a Google Document. The original
  26.   // file name is used as the title of the document and the MIME type
  27.   // is determined based on the extension on the original file name.
  28.   $newDocumentEntry = $docs->uploadFile($fileToUpload, $originalFileName,
  29.       null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);
  30.  
  31.   echo "New Document Title: ";
  32.  
  33.   if ($html) {
  34.       // Find the URL of the HTML view of this document.
  35.       $alternateLink = '';
  36.       foreach ($newDocumentEntry->link as $link) {
  37.           if ($link->getRel() === 'alternate') {
  38.               $alternateLink = $link->getHref();
  39.           }
  40.       }
  41.       // Make the title link to the document on docs.google.com.
  42.       echo "<a href=\"$alternateLink\">\n";
  43.   }
  44.   echo $newDocumentEntry->title."\n";
  45.   if ($html) {echo "</a>\n";}
  46. }

ドキュメントのフィードの検索

ドキュメントの一覧を検索するには、» 標準的な Google Data API クエリパラメータ を使用します。 カテゴリを使用して、ドキュメントの種類 (ワープロ文書、 スプレッドシート) を絞り込みます。 フルテキストのクエリ文字列を使用して、ドキュメントの全文検索を行います。 ドキュメントの一覧に固有のパラメータについての詳細な情報は、 » Documents List Data API リファレンスガイド を参照ください。

ワープロ文書の一覧の取得

指定した型のすべてのドキュメントを含むフィードを取得することもできます。 たとえば、ワープロ文書の一覧を取得するには、 次のようなカテゴリクエリを使用します。

  1. $feed = $docs->getDocumentListFeed(
  2.     'http://docs.google.com/feeds/documents/private/full/-/document');

スプレッドシートの一覧の取得

Google Spreadsheets の一覧を取得するには、 次のようなカテゴリクエリを使用します。

  1. $feed = $docs->getDocumentListFeed(
  2.     'http://docs.google.com/feeds/documents/private/full/-/spreadsheet');

テキストクエリの実行

ドキュメントの中身を検索するには、リクエスト内で Zend_Gdata_Docs_Query を使用します。 クエリオブジェクトを使用してクエリ URI を組み立て、 検索する単語をパラメータとして渡します。 これは、ある文字列を含むドキュメントを一覧から探すクエリの例です。

  1. $docsQuery = new Zend_Gdata_Docs_Query();
  2. $docsQuery->setQuery($query);
  3. $feed = $client->getDocumentListFeed($docsQuery);

Google Calendar の使用法