我正在尝试使用适用于 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。
我将不胜感激任何形式的帮助。