Google Cloud Platform Projects

Every Apps Script project uses the Google Cloud Platform to manage authorization, Advanced services, and other details. To configure and manage these settings, every Apps Script project has an associated Google Cloud Platform project (a GCP project). Your script project can use a default GCP project that is created automatically by Apps Script, or the script project can use a standard GCP project that you create yourself. In general, default GCP projects are good for everyday or simple scripts, but you should use a standard GCP project for any application that is complex, commercial quality, or is intended for publication.

You can switch a script project to use a standard GCP project at any time, but you can't switch back to use a default project. It's best to select the GCP project your script uses early in development, as switching later can cause complications, such as requiring your users to re-authorize.

Default Cloud Platform projects

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.

For most applications and scripts, you never need to see or adjust this default GCP project—Apps Script handles all the necessary interactions with the Google Cloud Platform automatically. Default GCP projects have the following properties:

  • When you enable an advanced service for your script project in the Apps Script editor, it is automatically enabled in the default GCP project when the script project is saved.
  • Default GCP projects function the same regardless of whether the associated script project file is in a regular Google Drive folder or in a shared drive.
  • If you delete the script project or switch it to use another GCP project, the default GCP project attached to the script is deleted along with any settings or information it contains.
  • The script project's Stackdriver logs aren't accessible via the Google Cloud Platform Console if a default GCP project is used. Instead, you can find a simplified listing of the Stackdriver logs in the Apps Script dashboard.
  • Default GCP projects aren't accessible from the Google Cloud Platform Console, meaning you can't edit the project settings directly.

  • For G Suite customers, default GCP projects fall under the Organization root > system-gsuite > apps-script folder in the Cloud Platform Resource Hierarchy. For non-G Suite customers, default GCP projects are unparented in the Resource Hierarchy.

For the majority of script projects, using the default GCP project is the best choice. However, certain tasks and applications require manually changing settings with the Google Cloud Platform Console and thus using a default GCP project isn't possible. In these cases, your script must use a standard GCP project instead.

Standard Cloud Platform projects

Default Cloud Platform projects are the best option for most script projects, as they are the easiest to use. However, default GCP projects can't be used for certain cases because they require you to manually configure the GCP project. In these situations, you must switch your script project to use a standard GCP project.

The following sections describe when a standard GCP project is required, the properties of such projects, and common tasks done with them. The tasks described below can only be conducted with standard GCP projects, as they require accessing the project in the Google Cloud Platform Console.

When standard GCP projects are required

The following situations require the use of a standard GCP project:

Standard GCP project properties

Standard GCP projects have the following properties:

  • You can access all of the Google Cloud settings for the project directly form the Google Cloud Platform Console. This lets you enable APIs, adjust authorization credentials, and conguire other details.
  • When a script project using a standard GCP project is deleted or switched to use another GCP project, the original GCP project remains and can be reused.
  • When you enable an advanced service in a script project, you must manually enable the corresponding API in the standard GCP project.
  • Multiple script projects and other apps can share the same standard GCP project. However, if you intend to publish a script project to the G Suite Marketplace as an add-on or domain-wide web app, it must have its own standard GCP project—published apps can't share GCP projects with other published apps.
  • If you want to execute functions in a script project from another app using the Apps Script API's scripts.run method, the script project and the calling application must share the same standard GCP project.
  • Standard GCP projects function the same regardless of whether the associated script project file is in a regular Google Drive folder or in a shared drive.
  • When Apps Script asks a user to authorize a script that uses a standard GCP project, the GCP project name is used to identify the script (not the script name). For this reason, be sure to set an appropriate GCP project name.

Accessing a standard GCP project

If you need to access the standard GCP project associated with your script project, do the following:

  1. Open the script in the Apps Script editor.
  2. Select Resources > Cloud Platform project.
  3. In the dialog that opens, click the top link that references the GCP project name.

This takes you directly to the standard GCP project that the script is currently using. You may be asked to accept a terms of service agreement if you have not done so already. If this procedure results in the dialog message "This script has an Apps Script managed Cloud Platform project.", it means that your script project is using a default GCP project rather than a standard GCP project.

In addition to accessing the GCP project from the Apps Script editor, you can locate a standard GCP project directly in the GCP console Manage Resources page.

Enabling an API in a standard GCP project

Often an Apps Script application needs access to another Google API. This requires you to enable the API in the corresponding GCP project. You can enable an API by doing the following:

  1. Open the GCP project.
  2. Click the menu icon in the upper-left to open the left nav.
  3. Select APIs & Services.
  4. Select add_box Enable APIs and Services.
  5. Use the search box to find the API you are looking for and then click the resulting API entry.
  6. Click Enable to enable the API for this GCP project.

During this process, you might be prompted to accept the Terms of Service for Google APIs or the Google Cloud Platform. Review the Terms of Service carefully before accepting them.

Depending on the application, you may also need to configure the API by clicking the settings icon for the API as listed in the APIs & Services dashboard.

Determining the ID and number of a standard GCP project

All GCP projects have a project name, project ID, and project number that is used to identify them. Occasionally you must have these identifiers to configure services or complete other tasks.

To determine your GCP project's ID and number, do the following:

  1. Open the GCP project.
  2. Click the more_vert icon in the upper-right and select Project settings.
  3. The Project name, Project ID, and Project number are displayed in the resulting Settings panel. The Project number consists only of digits, while the Project ID is alphanumeric. You can also edit the Project name from this panel; this name is used to identify your script application in authorization prompts.

Viewing Stackdriver logs and error reports in the Google Cloud Platform Console

If you are using Stackdriver logging or Stackdriver error reporting for your script project, you can view those logs and reports in the Google Cloud Platform Console by doing the following:

  1. Open the GCP project.
  2. Click the menu icon in the upper-left to open the left nav.
  3. To view Stackdriver logs, scroll down the left nav and select Logging > Logs in the Stackdriver section. If there are no logs to display, Stackdriver presents a "Welcome to StackDriver Logging" page.
  4. To view Stackdriver error reports, scroll down the left nav and select Error Reporting in the Stackdriver section. If you are prompted to "Set up Error Reporting" this is because your script project has not yet logged any exceptions.

When using services that require OAuth, users are prompted to authorize those services. The OAuth consent screen settings let you set some of the information that is presented to users when they are prompted to authorize, such as the application name and terms of service URL.

Default GCP projects create a consent screen automatically from the Apps Script project details; you can't adjust those settings. Standard GCP projects let you customize this information. You can configure your script's consent screen by doing the following:

  1. Open the GCP project.
  2. Click the menu icon in the upper-left to open the left nav.
  3. Select APIs & Services, then click Credentials.
  4. Select the OAuth consent screen tab.
  5. Fill in the consent screen form. At a minimum you must provide an Application name.
  6. Click Save to record your changes.

Creating OAuth credentials

Apps Script usually handles the work of setting up OAuth for the services your script uses. However, for some applications you must create additional OAuth credentials (client IDs and client secrets). You can only do this with standard GCP projects.

To create a client ID and client secret for your script project, do the following:

  1. Open the GCP project.
  2. Click the menu icon in the upper-left to open the left nav.
  3. Select APIs & Services, then click Credentials.
  4. Select the Credentials tab.
  5. In the Create credentials drop-down menu, select OAuth client ID.
  6. Under Application type, select Web application or Other and fill in the resulting form if needed. Click Create when finished.
  7. In the Credentials panel, find the client you created and click the get_app icon to download your credential file containing your client ID and client secret. You can use this file to configure OAuth.

Adding additional owners to a standard GCP project

You can add additional owners (or other roles) to a standard GCP project. If you are collaborating on a project, this helps ensure that someone on your team always has access to the script project's GCP settings.

You can add additional owners or other roles to a GCP project by doing the following. You must have edit permissions for the GCP project to make any of these changes:

  1. Determine who your collaborators should be. We recommended that you create or use an existing Google Group as your collaborator list. You can also specify domains in the collaborator list to include all users in that domain as collaborators.
  2. Open the script's Cloud Platform project.
  3. Click the menu icon in the upper-left to open the left nav.
  4. Select IAM & admin > IAM.
  5. At the top of the window, click the person_add ADD button.
  6. Follow the on-screen instructions to add one or more new members and their roles to the GCP project. You can add individual emails, Google Groups, or domains as new members.
  7. Click Save to record the changes.

Grouping multiple scripts with a single Cloud Platform project

It is possible to have multiple Apps Script projects share the same standard GCP project. To do this, create a new GCP project and then switch each script project to use it. Default GCP projects can't be used in this way.

Switching to a different standard GCP project

You can switch a script project so that it uses a different (standard) GCP project. This is necessary if your application requires manual configuration of the GCP project; see standard Cloud Platform projects for a list of cases where this is necessary). It's recommended that you select the GCP project your script uses early in development, as switching GCP projects later can cause complications, such as requiring users to re-authorize.

To switch a script's existing GCP project over to another GCP project, follow these steps:

  1. If you don't have a suitable GCP project, create a new one by following the Create a project instructions. Otherwise, open the GCP console Manage Resources page and locate an existing GCP project to use. You must have edit permissions for the GCP project and you must be able to view its settings in the Google Cloud Platform Console. The new project can't be one that was automatically created by Apps Script.
  2. Set a memorable GCP project name so that you can more easily locate it in the GCP console Manage Resources page. This name is also used to identify the script when Apps Script asks users to authorize it.
  3. Determine the Project number of your GCP project.
  4. In the Apps Script editor, open the script whose GCP project you want to replace.
  5. Click Resources > Cloud Platform project.
  6. In the Change Project section, paste the project number you copied into the text field, then click Set Project.
  7. A warning screen explains the effects of changing the Cloud Platform project. Read the notice carefully, and click Confirm.

GCP projects and shared drives

Shared drives (formerly "Team Drives") provide shared spaces where groups of Drive users can collaborate on Apps Script projects and Drive documents. Shared drives are valuable when developing scripts, add-ons, and web apps with a team, but they place some restrictions on what you can do with older default GCP projects.

The following list of restrictions describes how GCP projects interact with shared drives:

  • If your script project is using a standard GCP project, there are no additional restrictions when the script project resides in a shared drive.
  • If your script project uses a default GCP project that was created on or after April 8, 2019, there are no additional restrictions when the script project resides in a shared drive.
  • If your script project uses a default GCP project that was created before April 8, 2019, the following restrictions apply while the script project resides on a shared drive:
    1. You can't access the default GCP project using the Apps Script UI or the Google Cloud Platform Console. This restriction prevents you from taking actions that require direct access to the GCP project.
    2. Advanced services aren't available. You can only enable advanced services using standard GCP project if you script project file resides in a shared drive.
    3. When an existing Apps Script project is moved into a shared drive, access to the default GCP project is restricted. You can, however, still access the default GCP project if you had access prior to the move. For example, suppose you created a script in the root of your My Drive and then moved it into a shared drive. You could still access the script's GCP project but your collaborators may not be able to.
    4. A scripts retains the project name it had prior to being moved to a shared drive. Even if you change the project name on the shared drive, users that authorize the script still see the old name on authorization dialogs.

If you want to avoid the above restrictions for older scripts, you can switch to a standard GCP project.

发送以下问题的反馈:

此网页
Apps Script
Apps Script
需要帮助?请访问我们的支持页面