Advanced Google Services

The advanced services in Apps Script allow experienced developers to connect to certain public Google APIs with less set-up than using their HTTP interfaces. They work much like Apps Script's built-in services — for example, they offer autocomplete, and Apps Script handles the authorization flow automatically — but are not enabled by default.

To see which Google APIs are available as advanced services, look for the "Advanced Google Services" section in the Reference. If you want to use a Google API that isn't available as an advanced service, just connect to it like any other external API.

Requirements

Enabling advanced services requires that you have access to the script's Cloud Platform project. When you collaborate on a project in Team Drives, your access to the Cloud Platform project may be restricted; see the Cloud Project and Team Drives guide section for details.

You may wish to switch the Apps Script to use a standard Cloud Platform project in order to have direct access to the API monitoring information in the API Console dashboard. Doing so also ensures you and your collaborators have access to the Cloud Platform project settings while the script resides in a Team Drive.

Enabling advanced services

To use an advanced Google service, follow these instructions:

  1. In the script editor, select Resources > Advanced Google services....
  2. In the dialog that appears, click the on/off switch next to the service you want to use.
  3. At the bottom of the dialog, click the link for the Google API Console.
  4. In the console, click into the filter box and type part of the name of the API (for example, "Calendar"), then click the name once you see it.
  5. On the next screen, click Enable API.
  6. Close the API Console and return to the script editor. Click OK in the dialog. The advanced service you enabled is now available in autocomplete.

How method signatures are determined

Advanced services generally use the same objects, method names, and parameters as the corresponding public APIs, although method signatures are translated for use in Apps Script. The script editor's autocomplete function usually provides enough information to get started, but the rules below explain how Apps Script generates a method signature from a public Google API.

Requests to Google APIs can accept a variety of different types of data, including path parameters, query parameters, a request body, and/or a media upload attachment. The corresponding method signature in Google Apps Script has the following arguments:

  1. The request body (usually a resource), as a JavaScript object.
  2. Path or required parameters, as individual arguments.
  3. The media upload attachment, as a Blob argument.
  4. Optional parameters, as a JavaScript object mapping parameter names to values.

If the method doesn't have any items in a given category, that part of the signature is omitted.

There are some special exceptions to be aware of:

  • For methods that accept a media upload, the parameter uploadType is set automatically.
  • Methods named delete in the Google API are named remove in Apps Script, since delete is a reserved word in JavaScript.

发送以下问题的反馈:

此网页
Apps Script
Apps Script