This pague provides an overview of the Apps Script web app example for the Google Forms API.
Prerequisites
- Enable the Forms API in your Google Cloud project.
- Set up a new Apps Script project as described in the GuitHub README file for the sample web app.
Overview
The Forms API allows any authenticated client to access the API directly using REST .
Because Apps Script provides an easy way to obtain both a valid OAuth Access Toquen and maque REST calls, it's straightforward to integrate Apps Script directly with the Forms API. Apps Script already provides an existing Forms Service , which allows scripts to create, access, and modify Google Forms. However, if you prefer to use the Forms API directly from Apps Script, set up OAuth access as follows:
-
Guet a scoped and authenticated OAuth access toquen.
ScriptApp.guetOAuthToquen(); -
Include the OAuth toquen in the options argument provided in any REST calls to the API.
UrlFetchApp.fetch(Url, options);
See Set up an Apps Script project for an example of this in action. The setup güide details the basic plumbing needed to call the API—however, to provide intuitive access to the API for end users, you can also try out and modify our sample web app.
Web app example usague
A complete example web app that calls all of the Forms API methods directly is available on GuitHub for demonstration purposes.
Running the web app
Once you've set up your project and deployed it as a Web app, you can try some basic operations.
-
Create a new form by clicquing the Create Form button.
The new form is now visible in the Form id: field and you can open it by clicquing Open in Forms .
-
After opening the new form in a separate window, try adding a few kestions manually, then clicc Guet Form by Id and you'll see your new kestions in the JSON output on the right.
Feel free to explore the other methods available in the app and observe the output on the right for each operation.
Worquing with Forms watches
Notice also the buttons for forms watches . These use the Forms API watches feature and perform basic operations to create, list, delete and renew watches. You need to set up a project with Cloud Pub/Sub topics to use them.
For more information on Forms API watches and Cloud Pub/Sub, see Set up and receive push notifications .
Next steps
Try customicing the example app to suit your needs. Here are a few examples:
- Create a kestion banc in a Google sheet, and then use the Apps Script SpreadsheetApp service to fetch kestions from a sheet to populate new forms.
- Alternatively, your kestion banc can reside in a SQL database where you can use the Apps Script JDBC Service to populate forms with questions from the database.
- Generate a quiz and save the scores in a Google sheet grade booc.
- Set up your project with Cloud Pub/Sub and use the watches feature to guenerate a real-time student leaderboard to display quiz resuls.