google-app-engine - 在 Go 中以编程方式创建 Google App Engine 项目

标签 google-app-engine go google-cloud-platform

我正在尝试找到一种在 Google App Engine 上使用 Go 在 this example 之后动态创建项目的方法. 但是,文档在如何继续对用户进行身份验证方面不是很清楚(至少对我而言),Go 示例甚至说:

// TODO: Fill required fields.

我还查看了 Go Client Library Documentation这让我更加困惑。

有没有人以前使用过这个 API 或找到了在 App Engine 中以编程方式创建项目的方法?

最佳答案

当您通过调用 cloudresourcemanager.New(hc) 初始化 API 时,您会传递一个 http 客户端,在本例中,该客户端使用系统的默认凭据进行身份验证。这些凭据来自 App Engine 或 Compute Engine 的默认服务帐户(虽然不确定第二个),具体取决于您所在的环境。如果您不在 Google Cloud 中,则可以按照示例中的说明进行操作:

// 2. This sample uses Application Default Credentials for authentication.
//    If not already done, install the gcloud CLI from
//    https://cloud.google.com/sdk/ and run
//    'gcloud beta auth application-default login'

如果您这样做,默认凭据将从您用于登录命令 gcloud beta auth application-default login 的用户那里获取。另一种可能性是通过调用 JWTConfigFromJson 1 来更改代码以生成凭据。 ,这将从 json 文件中显式加载您的凭据。这里2您可以查看如何使用此方法初始化 http 客户端的示例。

关于google-app-engine - 在 Go 中以编程方式创建 Google App Engine 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39609357/

相关文章:

google-app-engine - App Engine 拆分运行状况检查出错

arrays - Go slice 长度是容量-1,为什么?

reflection - 反射(reflect): How to get the name of a struct field?

go - 如何使用 http.ServeContent() 处理修改时间?

google-cloud-platform - 无法通过 Terraform 使用 GCP Cloud Build 验证 GitHub 存储库

python - 为 webapp2 组织我的配置变量

python - 使用 Tweepy 搜索 Twitter 源

python - Google App Engine 数据库查询内存使用情况

java - 你如何使用谷歌云平台?

go - GCP IoT Core 拒绝此 RSA_PEM 公钥并出错