启用 Google Workspace API

在使用 Google API 之前,您需要在 Google Cloud 项目中启用这些 API。您可以在单个 Google Cloud 项目中启用一个或多个 API。 如果您还没有 Google Cloud 项目,请参阅创建 Cloud 项目。

如需在 Cloud 项目中启用 API,请执行以下操作:

Google Cloud 控制台

  1. 在 Google Cloud 控制台中,依次点击“菜单” > API 和服务 > 库 > Google Workspace。

    转到 API 库

  2. 点击您要启用的 API。
  3. 点击启用。
  4. 如需启用更多 API,请重复上述步骤。

Google Cloud CLI

  1. 安装或打开 Google Cloud 命令行界面 (CLI)。
  2. 运行 services enable 命令,指定要启用的 API 服务。

    gcloud services enable API_SERVICE_ID

Google AI Studio 中预先启用的 API

在 Google AI Studio 中构建 Web 应用时,您无需在 Google Cloud 控制台中手动启用受支持的 Google Workspace API。以下 API 已在 Google 管理的新手体验层级项目中预先启用:

  • Google Calendar API (calendar-json.googleapis.com)
  • Google Docs API (docs.googleapis.com)
  • Google Drive API (drive.googleapis.com)
  • Google Forms API (forms.googleapis.com)
  • Gmail API (gmail.googleapis.com)
  • Google Picker API (picker.googleapis.com)
  • Google Sheets API (sheets.googleapis.com)
  • Google Slides API (slides.googleapis.com)
  • Google Tasks API (tasks.googleapis.com)

在新手体验层级项目中,Google Workspace API 仅支持客户端 OAuth 2.0。例如,Google Picker API 使用 OAuth 2.0 访问令牌,而不是开发者 API 密钥,并且不支持服务账号或在 Secret Manager 中存储 OAuth 客户端密钥。如果您需要服务器端凭据、API 密钥或其他 API(例如 Admin SDK API 或 Google Apps 脚本 API),可以将新手体验层级项目升级为标准云项目,然后手动配置这些凭据、密钥或 API。

如需详细了解新手体验层级的配额和功能,请参阅新手体验层级概览和从 Google AI Studio 部署 Web 应用。

(可选)在实验性应用中试用 Google Workspace API

如果您正在试用 Google Workspace,请使用以下快捷方式,该快捷方式会启用常用的 Google Workspace API,并创建可供您使用的 OAuth 凭据。

如果您正在开发一款会访问用户信息应用,则必须在发布应用之前配置 OAuth 权限请求页面。

点击此按钮可选择或创建 Google Cloud 项目,并自动启用 Workspace API:

启用 Workspace API

在随即显示的对话框中,点击下载客户端配置,并将 credentials.json 保存到工作目录。

如需查看所有可用 API 的完整列表,并从浏览器中试用特定方法,请参阅 Google Workspace API Explorer。

已启用的 API(点击可展开)

该按钮会启用以下 API:

  • Admin SDK/API
  • Apps Script API
  • Calendar API
  • Chat API
  • Classroom API
  • Docs API
  • Drive API
  • Forms API
  • Gmail API
  • Google Workspace Add-ons API
  • Google Keep API
  • Meet REST API
  • Sheets API
  • Slides API

Google Workspace API

使用以下 Google Cloud 控制台链接或 Google Cloud 命令行界面 (CLI) 在云项目中启用特定的 Google Workspace API。

启用 Admin SDK API
gcloud services enable admin.googleapis.com
启用 Alert Center API
gcloud services enable alertcenter.googleapis.com
启用 Apps 脚本 API
gcloud services enable script.googleapis.com
启用 CalDAV API
gcloud services enable caldav.googleapis.com
启用 Calendar API
gcloud services enable calendar-json.googleapis.com
启用 Chat API
gcloud services enable chat.googleapis.com
启用 Classroom API
gcloud services enable classroom.googleapis.com
启用 Cloud Identity API
gcloud services enable cloudidentity.googleapis.com
启用 Cloud Search API
gcloud services enable cloudsearch.googleapis.com
启用 Docs API
gcloud services enable docs.googleapis.com
启用 Drive API
gcloud services enable drive.googleapis.com
启用 Drive Activity API
gcloud services enable driveactivity.googleapis.com
启用 Drive Labels API
gcloud services enable drivelabels.googleapis.com
启用 Forms API
gcloud services enable forms.googleapis.com
启用 Gmail API
gcloud services enable gmail.googleapis.com
启用 Groups Migration API
gcloud services enable groupsmigration.googleapis.com
启用 Groups Settings API
gcloud services enable groupssettings.googleapis.com
启用 Google Workspace Add-ons API
gcloud services enable gsuiteaddons.googleapis.com
启用 Google Keep API
gcloud services enable keep.googleapis.com
启用 Enterprise License Manager API
gcloud services enable licensing.googleapis.com
启用 Marketplace API
gcloud services enable appsmarket.googleapis.com
启用 Marketplace SDK
gcloud services enable appsmarket-component.googleapis.com
启用 Meet REST API
gcloud services enable meet.googleapis.com
启用 People API
gcloud services enable people.googleapis.com
启用 Postmaster Tools API
gcloud services enable gmailpostmastertools.googleapis.com
启用 Reseller API
gcloud services enable reseller.googleapis.com
启用 Sheets API
gcloud services enable sheets.googleapis.com
启用 Slides API
gcloud services enable slides.googleapis.com
启用 Tasks API
gcloud services enable tasks.googleapis.com
启用 Vault API
gcloud services enable vault.googleapis.com

下一步

了解 Google Workspace API 的身份验证和授权机制。