Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Created July 5, 2019 02:03
Show Gist options
  • Save tanaikech/e945c10917fac34a9d5d58cad768832c to your computer and use it in GitHub Desktop.
Save tanaikech/e945c10917fac34a9d5d58cad768832c to your computer and use it in GitHub Desktop.
Linking Cloud Platform Project to Google Apps Script Project

Linking Cloud Platform Project to Google Apps Script Project

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.

5. Link Cloud Platform Project to GAS project.

  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:

@deadlysyn
Copy link

Hey thanks for the writeup! This saved me some time. ❤️

@danvoronov
Copy link

danvoronov commented Jun 28, 2021

after all this steps i still get on GPhotoApp.getAlbumList(); === Error: { "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name "nextPageToken": Cannot bind query parameter. Field 'nextPageToken' could not be found in request message.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ { "description": "Invalid JSON payload received. Unknown name "nextPageToken": Cannot bind query parameter. Field 'nextPageToken' could not be found in request message." } ] } ] } }

@baublys
Copy link

baublys commented Oct 22, 2021

Thanx for article!
How from google cloud console to jump GAS project code?

@PMULOT
Copy link

PMULOT commented Nov 10, 2021

I have exactly the same error and I don't what to do ! :
Error: { "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name "nextPageToken": Cannot bind query parameter. Field 'nextPageToken' could not be found in request message.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ { "description": "Invalid JSON payload received. Unknown name "nextPageToken": Cannot bind query parameter. Field 'nextPageToken' could not be found in request message." } ] } ] } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment