Google Apps Script のクイックスタート

クイックスタートでは、 Google Workspace API

Google Workspace クイックスタートでは、API クライアント ライブラリを使用して 認証と認可のフローの詳細を確認できます。おすすめの方法 独自のアプリ用のクライアント ライブラリを使用します。このクイックスタートでは、 テストに適したシンプルな認証アプローチ できます。本番環境では、Terraform の IAM 構成の 認証と認可 次の日付より前 アクセス認証情報の選択 選択することもできます

作成: Google Apps Script Google Docs API にリクエストを送信する API です。

目標

  • 環境を構成します。
  • スクリプトを作成して構成する。
  • スクリプトを実行します。

前提条件

  • Google アカウント
  • Google ドライブへのアクセス

スクリプトを作成する

  1. script.google.com/create にアクセスして新しいスクリプトを作成します。
  2. スクリプト エディタの内容を次のコードに置き換えます。

docs/quickstart/quickstart.gs
/**
 * Prints the title of the sample document:
 * https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
 * @see https://developers.google.com/docs/api/reference/rest/v1/documents/get
 */
function printDocTitle() {
  const documentId = '195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE';
  try {
    // Get the document using document id
    const doc = Docs.Documents.get({'includeTabsContent': true}, documentId);
    // Log the title  of document.
    console.log('The title of the doc is: %s', doc.title);
  } catch (err) {
    // TODO (developer) - Handle exception from Docs API
    console.log('Failed to found document with an error %s', err.message);
  }
}

  1. [保存] をクリックします。
  2. [無題のプロジェクト] をクリックし、 クイックスタートをクリックし、[名前を変更] をクリックします。

スクリプトを構成する

Google Docs API を有効にする

  1. Apps Script プロジェクトを開きます。
  1. [編集者] をクリックします。
  2. [サービス] の横にある [サービスを追加] をクリックします。
  3. 選択 Google Docs API [追加] をクリックします。

サンプルの実行

Apps Script エディタで、[実行] をクリックします。

サンプルを初めて実行すると、アクセスの承認を求められます。

  1. [権限を確認] をクリックします。
  2. アカウントを選択してください。
  3. [許可] をクリックします。

スクリプトの実行ログがウィンドウの下部に表示されます。

<ph type="x-smartling-placeholder"> <ph type="x-smartling-placeholder">

次のステップ