【发布时间】:2017-12-02 06:44:20
【问题描述】:
我正在尝试使用 Google Cloud SDK 在 Java 中以编程方式为未在 App/Compute 引擎上运行的应用程序创建服务帐户密钥。 This question 与我的类似,但它在 App 引擎上运行,所以我不能使用与它使用来自 App Engine API 的类相同的代码。
相关代码如下。我的问题是 AppIdentityCredential 是 AppEngine API 的一部分,因此不能在这里使用。我可以作为参数传入什么? new Builder() 方法中的第三个参数接受HttpRequestInitializer,但我不明白我应该传入这个接口的什么实现。感谢任何帮助。
import com.google.api.services.iam.v1.Iam;
import com.google.api.services.iam.v1.model.CreateServiceAccountKeyRequest;
import com.google.api.services.iam.v1.model.ServiceAccountKey;
AppIdentityCredential credential = new AppIdentityCredential(
Arrays.asList("https://www.googleapis.com/auth/cloud-platform"));
Iam iam = new Iam.Builder(httpTransport, JSON_FACTORY,credential)
.setApplicationName(APPLICATION_NAME).build();
ServiceAccountKey key = iam.projects().serviceAccounts().keys()
.create(SERVICE_ACCOUNT_RESOURCE_NAME, new CreateServiceAccountKeyRequest()).execute();
【问题讨论】:
标签: java google-app-engine google-cloud-platform google-oauth-java-client google-iam