Linking Cloud Platform Project to Google Apps Script Project

Gists

Introduction

At April 8, 2019, the specification of Google Apps Script Project was changed. You can see this at Google Cloud Platform Projects. The official document says as follows.

Warning: Starting on or after April 8, 2019, the Google Cloud Platform Console won’t be able to access the default GCP projects created for new Apps Script projects. Older, existing scripts may have default GCP projects that are still accessible, however. If you have a new script and require access to its GCP project from the Google Cloud Platform Console, you must use a standard GCP project.

And then,

When a new Apps Script project is created, a default GCP project is also created behind the scenes. This GCP project is hidden, meaning most users aren’t able to directly locate, view, or update the project in the Google Cloud Platform Console. However, admins and domain users that have the resourcemanager.projects.list permission on the parenting GCP folder are able to view and configure default projects.

By this, when users create new Google Apps Script Project (the container-bound script and the standalone script) after April 8, 2019, it is required to link Cloud Platform Project to the created Google Apps Script Project (GAS project). In this document, I would like to introduce the flow for linking Cloud Platform Project to GAS project.

Linking Cloud Platform Project to Google Apps Script Project

In this section, by creating new Cloud Platform Project and new GAS project, the flow for linking Cloud Platform Project to GAS project is explained.

1. Create new GAS project.

  1. In this case, you can create the projects of the container-bound script type and the standalone script type. When the GAS project is created after April 8, 2019, when you see “Resource” -> “Cloud Platform Project” at the script editor, the following screen can be seen.
  2. By this This script has an Apps Script–managed Cloud Platform project., when users want to use Google APIs except for Advanced Google Services, it is required to link Cloud Platform Project to this GAS project.

2. Create new Cloud Platform Project

  1. Access to Manage resources of Google Cloud Platform. And click “CREATE PROJECT” like below.
    • If you want to use the existing Cloud Platform Project, please use this.
  2. Input the project name and click “CREATE” button.
  3. You can see the created Cloud Platform Project by reloading “Manage resources of Google Cloud Platform”.
  4. For the cerated Cloud Platform Project, open the setting page by clicking “Settings” like below.

3. Retrieve the project number.

  1. You can retrieve the project number like below. In this case, it’s 123456789012.

4. Create new credential.

When new Cloud Platform Project is created, there are no credentials. So when users want to use Google API from outside, it is required to create new credentials. In the most cases, this situation is required. So here, I would like to introduce to create new credentials. On the other hand, the GAS project linked to Cloud Platform Project automatically creates the credential.

  1. From the navigation menu like below, and jump to “Credentials”
  2. Before create the credential, open “OAuth concent screen” like below. And input “Application name” and click “Save” button.
  3. Create new credential. Create OAuth client ID like below.
  4. Select “Web application” and input “Name”. Then, click “Create” button.
  5. By this, new credential could be created.
  1. Open the script editor which is the created new GAS project.
  2. Open a dialog by “Resource” -> “Cloud Platform Project” at the script editor. You can see below dialog.
  3. Put the retrieved project number to “Enter Project Number here”.
  4. Click “Set Project”. And click “Confirm” button.
  5. When “Success! Project Changed” is shown, it means that Cloud Platform Project was linked to GAS project.
  6. At this time, if “Close” button cannot be used, you can close the dialog by clicking “X” button at the top right.

Note:

Reference:

 Share!