【发布时间】:2021-09-19 07:15:33
【问题描述】:
我正在尝试使用适用于 Node.js 的官方 Google SDK 来自动化整个项目创建过程。对于项目创建,我使用资源管理器 SDK:
const resource = new Resource();
const project = resource.project(projectName);
const [, operation,] = await project.create();
我还必须启用一些服务才能在此过程中使用它们。当我跑步时:
const client = new ServiceUsageClient();
const [operation] = await client.batchEnableServices({
parent: `projects/${projectId}`,
serviceIds: [
"apigateway.googleapis.com",
"servicecontrol.googleapis.com",
"servicemanagement.googleapis.com",
]
});
我收到:
Service Usage API has not been used in project 1014682171642 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/serviceusage.googleapis.com/overview?project=1014682171642 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
当我通过 API 创建项目时,我发现默认情况下未启用服务使用 API 很可疑。显然,如果我必须手动启用某些东西,那么使用 API 会带来好处。当我通过 Can Console 创建项目时,默认情况下会启用服务使用 API,因此此问题仅影响 API。也许还有其他方式可以以编程方式启用服务使用 API。
我将不胜感激任何形式的帮助。
【问题讨论】:
-
您需要启用
serviceusage.googleapis.com。问题是什么? Stack Overflow 不是讨论供应商政策或服务要求的地方。将您的问题转化为编程问题。 -
我在 Google Cloud 集体中提出一个编程问题。该问题与如何仅使用公共 API 以编程方式启用服务使用 API 而无需触摸 Cloud Console 相关。与政策或服务要求无关。
-
您在启用 API 时遇到什么问题?您的问题包含
I find it suspicious字样,它要求提供离题的意见。重写您的问题以清楚地说明问题,包括您编写的代码和您的代码生成的错误消息。 -
某些 API 默认启用,serviceusage.googleapis.com 不是其中之一,无论您是否觉得它可疑 :)
-
@jabbson 如您在此处看到的 cloud.google.com/service-usage/docs/enabled-service#default 服务使用 API 被列为默认服务之一。他们还提到这适用于 SDK,所以也许我在这个难题中遗漏了一些东西。
标签: node.js google-cloud-platform google-cloud-sdk google-cloud-console google-cloud-resource-manager