フォーム作成者が回答できるユーザーをより細かく制御できるように、回答者に対するきめ細かい制御機能が導入されます。2026 年 1 月 31 日以降に API を使用して作成されたフォームは、デフォルトで公開状態になります。詳細については、
Google フォームの API の変更をご覧ください。
Apps Script サンプル ウェブアプリ
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このページでは、Google Forms API の Apps Script ウェブアプリの例の概要について説明します。
前提条件
- Google Cloud プロジェクトで Forms API を有効にします。
- サンプル ウェブアプリの GitHub README ファイルに記載されている手順に沿って、新しい Apps Script プロジェクトを設定します。
概要
Forms API を使用すると、認証済みのクライアントは REST を使用して API に直接アクセスできます。
Apps Script では、有効な OAuth アクセス トークンを取得し、REST 呼び出しを簡単に行うことができるため、Apps Script を Forms API に直接統合するのは簡単です。Apps Script には、スクリプトで Google フォームの作成、アクセス、変更を可能にする既存のフォーム サービスが用意されています。ただし、Apps Script から直接 Forms API を使用する場合は、次のように OAuth アクセスを設定します。
スコープが設定され、認証済みの OAuth アクセス トークンを取得します。
ScriptApp.getOAuthToken();
API への REST 呼び出しで指定する options 引数に OAuth トークンを含めます。
UrlFetchApp.fetch(Url, options);
実際にこの方法を使用する例については、Apps Script プロジェクトを設定するをご覧ください。設定ガイドでは、API の呼び出しに必要な基本的なプラグインの詳細について説明しています。ただし、エンドユーザーが API に直感的にアクセスできるようにするには、サンプル ウェブアプリを試して変更することもできます。
ウェブアプリの使用例
すべての Forms API メソッドを直接呼び出す完全なサンプル ウェブアプリは、デモ用に GitHub で入手できます。
ウェブアプリの実行
プロジェクトを設定してウェブアプリとしてデプロイしたら、基本的な操作を試すことができます。
[フォームを作成] ボタンをクリックして、新しいフォームを作成します。
新しいフォームが [フォーム ID:] フィールドに表示され、[フォームで開く] をクリックして開くことができます。
新しいフォームを別のウィンドウで開き、いくつかの質問を手動で追加して、[Get Form by Id] をクリックします。右側の JSON 出力に新しい質問が表示されます。
アプリで利用可能な他のメソッドを試し、各オペレーションの右側の出力を確認してください。
フォームのウォッチの操作
フォームのウォッチ用のボタンも確認してください。これらは、Forms API のウォッチ機能を使用して、ウォッチの作成、一覧表示、削除、更新の基本的なオペレーションを実行します。これらのトピックを使用するには、Cloud Pub/Sub トピックを含むプロジェクトを設定する必要があります。
Forms API ウォッチと Cloud Pub/Sub の詳細については、プッシュ通知を設定して受信するをご覧ください。
次のステップ
サンプルアプリをニーズに合わせてカスタマイズしてみてください。いくつか例を挙げましょう。
- Google スプレッドシートに問題バンクを作成し、Apps Script の SpreadsheetApp サービスを使用してスプレッドシートから質問を取得し、新しいフォームに入力します。
- または、質問バンクを SQL データベースに配置し、Apps Script の JDBC サービスを使用して、データベースの質問をフォームに入力することもできます。
- テストを生成して、スコアを Google スプレッドシートの成績簿に保存します。
- Cloud Pub/Sub を使用してプロジェクトを設定し、ウォッチ機能を使用してリアルタイムの学生リーダーボードを生成して、クイズの結果を表示します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-04-09 UTC。
[null,null,["最終更新日 2025-04-09 UTC。"],[],["This content details using Apps Script with the Google Forms API. Key actions include enabling the Forms API and setting up an Apps Script project. It demonstrates obtaining an OAuth access token via `ScriptApp.getOAuthToken()` and making REST calls with `UrlFetchApp.fetch()`. A web app example allows users to create forms, view them by ID, and interact with API methods. Additionally, it highlights the use of Forms API watches with Cloud Pub/Sub for creating, listing, deleting, and renewing watches. The app can be customized to suit specific needs.\n"],null,["# Apps Script sample web app\n\nThis page provides an overview of the Apps Script web app example for the\nGoogle Forms API.\n\nPrerequisites\n-------------\n\n- Enable the Forms API in your Google Cloud project.\n- Set up a new Apps Script project as described in the [GitHub README file](https://github.com/googleworkspace/apps-script-samples/blob/main/forms-api/demos/AppsScriptFormsAPIWebApp/README.md) for the sample web app.\n\nOverview\n--------\n\nThe Forms API allows any authenticated client to access the API\ndirectly using [REST](https://www.codecademy.com/article/what-is-rest).\n\nBecause Apps Script provides an easy way to obtain both a valid\n[OAuth Access Token](https://oauth.net/2/access-tokens/) and make REST calls,\nit's straightforward to integrate Apps Script directly with the Forms API.\nApps Script already provides an existing\n[Forms Service](/apps-script/reference/forms), which allows scripts to create,\naccess, and modify Google Forms. However, if you prefer to use the\nForms API directly from Apps Script, set up OAuth access as follows:\n\n1. Get a scoped and authenticated OAuth access token.\n\n `ScriptApp.getOAuthToken();`\n2. Include the OAuth token in the *options* argument provided in any REST\n calls to the API.\n\n `UrlFetchApp.fetch(Url, options);`\n\nSee\n[Set up an Apps Script project](/workspace/forms/api/guides/forms-apps-script)\nfor an example of this in action. The setup guide details the basic plumbing\nneeded to call the API---however, to provide intuitive access to the API for\nend users, you can also try out and modify our sample web app.\n\nWeb app example usage\n---------------------\n\nA complete example web app that calls all of the Forms API methods directly\nis available on\n[GitHub](https://github.com/googleworkspace/apps-script-samples/tree/main/forms-api/demos/AppsScriptFormsAPIWebApp)\nfor demonstration purposes.\n\n### Running the web app\n\nOnce you've set up your project and deployed it as a Web app, you can try some\nbasic operations.\n\n1. Create a new form by clicking the **Create Form** button.\n\n The new form is now visible in the **Form id:** field and you can open it by\n clicking **Open in Forms**.\n2. After opening the new form in a separate window, try adding a few questions\n manually, then click **Get Form by Id** and you'll see your new questions\n in the JSON output on the right.\n\nFeel free to explore the other methods available in the app and observe the\noutput on the right for each operation.\n\n### Working with Forms watches\n\nNotice also the buttons for forms\n[watches](/workspace/forms/api/reference/rest/v1/forms.watches). These use the\nForms API watches feature and perform basic operations to\ncreate, list, delete and renew watches. You need to set up a project with\n[Cloud Pub/Sub](https://cloud.google.com/pubsub) topics to use them.\n\nFor more information on Forms API watches and Cloud Pub/Sub, see\n[Set up and receive push notifications](/workspace/forms/api/guides/push-notifications).\n\nNext steps\n----------\n\nTry customizing the example app to suit your needs. Here are a few examples:\n\n- Create a *question bank* in a Google sheet, and then use the Apps Script [SpreadsheetApp](/apps-script/reference/spreadsheet/spreadsheet-app) service to fetch questions from a sheet to populate new forms.\n- Alternatively, your question bank can reside in a SQL database where you can use the Apps Script [JDBC Service](/apps-script/reference/jdbc) to populate forms with questions from the database.\n- Generate a quiz and save the scores in a Google sheet grade book.\n- Set up your project with Cloud Pub/Sub and use the [watches](/workspace/forms/api/guides/push-notifications) feature to generate a real-time student leaderboard to display quiz results."]]