Ala*_*xus 18 google-translate google-cloud-platform
我尝试在我的开发中使用 Google Translate API,但我找不到获取“service_account.json”文件的方法。
“Console Google Cloud Platform”的步骤:
控制台上的步骤:
拜托,我需要详细的步骤,因为我从谷歌得到的东西对我不起作用
HJE*_*JED 27
您需要在上面链接的页面上的“OAuth 同意屏幕”选项卡上填写所有必填字段,如果不存在则创建一个。
如果仍然不起作用,您可能还需要创建一个客户端 ID(抱歉,我不记得了)。
您需要创建一个服务帐户。
转到https://console.cloud.google.com/iam-admin/serviceaccounts/project并单击“创建服务帐户”
小智 17
获取 credential.js 的最新方法是单击“your_email_servicer”-> 选择 Tab 键,然后单击 [添加密钥]

小智 6
服务帐户密钥只能在第一次创建 sa 时检索,特别是在您通过 GCP 控制台执行此操作的情况下,这是一种安全机制。但这没什么大不了的,你可以删除旧的并创建一个新的,就这样,SA仍然保持不变,轮换密钥很好。
如果您使用 GDM(Google 部署管理器)或 Terraform 等 IaC,您可以根据需要多次检索它。
对于 Terraform,只需配置必要的输出,如下所示......
### Resources
resource "google_service_account" "my_service_account_name" {
account_id = "my-sa"
display_name = "my-sa"
description = "This is for descriptions"
}
resource "google_service_account_key" "my_service_account_key" {
service_account_id = google_service_account.my_service_account_name.name
}
### Outputs
output "my_service_account_key" {
description = "This is for descriptions (for single use)."
# sensitive = true # you can add sensitive to avoid showing it in plain text each time you run the code in case you don't need to retrieve it each time
value = base64decode(google_service_account_key.my_service_account_key.private_key)
}
Run Code Online (Sandbox Code Playgroud)
对于 GDM,请记住 GCP 不再建议将其用于 IaC 管理,您仍然可以使用描述资源的 CLI 来检索它并为 sa 关键资源添加基本的 jq 查询...
gcloud deployment-manager deployments describe my-gdm-deployment-name \
--project project-name \
--format json | jq -r '.outputs[] | select(.name==my-sa-key-resource-name") | .finalValue'| base64 --decode
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28716 次 |
| 最近记录: |