Create a Target Project to Execute with the Apps Script API

Before you can begin the Android or iOS quickstarts, you need a target Apps Script project. The mobile quickstart code executes a function in this project remotely, and receives a response back.

Follow these steps to create a simple script project and enable it for API access.

Step 1: Create the script

  1. Create a new script project.
  2. At the top, click Untitled Project to rename the script. Name the script "Apps Script API Quickstart Target" and click Rename.
  3. Replace the contents of the Code.gs file with the following:

    apps-script/execute/target.js
    /**
     * Return the set of folder names contained in the user's root folder as an
     * object (with folder IDs as keys).
     * @return {Object} A set of folder names keyed by folder ID.
     */
    function getFoldersUnderRoot() {
      const root = DriveApp.getRootFolder();
      const folders = root.getFolders();
      const folderSet = {};
      while (folders.hasNext()) {
        const folder = folders.next();
        folderSet[folder.getId()] = folder.getName();
      }
      return folderSet;
    }
  4. At the top, click Save .

Step 2: Switch to a user-managed Google Cloud project

Your Apps Script project is automatically associated with a default Apps Script-managed Google Cloud project. To deploy the script for API execution, you need to switch its association to a standard, user-managed Google Cloud project.

  1. In the Google Cloud console, go to the Manage resources page.
  2. At the top, click Create Project.
  3. Enter a project name, choose the parent organization, and select a location folder.
  4. Click Create.
  5. In the dialog that appears after the project is created, click Select project.
  6. On the project dashboard page under Project info, copy the project number.

To switch your Apps Script's Google Cloud project association, you need to configure the Google Cloud project's OAuth consent screen.

  1. From the Google Cloud project dashboard page, click Navigation menu > APIs & Services > OAuth consent screen.
  2. For the purposes of this quickstart, under User type, click External. If you're building an app for only your organization, you can select Internal.
  3. Click Create.
  4. Under App information in the App name field, enter "Apps Script API Quickstart Target."
  5. In the required email fields under User support email and Developer contact information, enter your email. For the purposes of this quickstart, you can leave the other optional fields blank. When you build an app for real-world use, fill out all of the consent screen fields accordingly.
  6. Click Save and Continue. For the purposes of this quickstart, you can keep clicking Save and Continue until you reach the Summary page. When you build an app for real-world use, fill out all of the pages accordingly.

Step 4: Deploy the script for execution

Now that you've set up your standard Google Cloud project, switch your Apps Script project's Google Cloud project association to use the standard user-managed project and deploy the script.

  1. In the Apps Script project, at the left, click Project settings .
  2. Under "Google Cloud Platform (GCP) Project," click Change project.
  3. In the "GCP project number" field, paste the standard GCP project number you copied in step 2.
  4. Click Set project.
  5. At the top right, click Deploy > New Deployment.
  6. In the dialog that opens, click Enable deployment types > API Executable.
  7. Under "Description" enter "Target-v1."
  8. Click Deploy.

Step 5: Choose a quickstart

Each of these quickstarts use the Apps Script API to execute the script you just created: