gpt4 book ai didi

java - 应用程序默认凭据无法创建 Google App Engine 服务帐户凭据

转载 作者:行者123 更新时间:2023-11-30 01:59:14 24 4
gpt4 key购买 nike

我正在开发一个应用程序,该应用程序使用部署在 AppEngine 上的其余端点来启动 Google VM 实例。

初始化 Compute Engine API 时,我提供应用程序默认凭据(因为我预计这将返回 AppEngine 服务帐户凭据)

GoogleCredential credential = GoogleCredential.getApplicationDefault();
if (credential.createScopedRequired()) {
List<String> scopes = new ArrayList<>();
// Set Google Compute Engine scope to Read-write.
scopes.add(ComputeScopes.COMPUTE);
credential = credential.createScoped(scopes);
}
return new Compute.Builder(httpTransport(), jsonFactory(), credential)
.setApplicationName(env.getProperty("spring.application.name"))
.build();

但我最终遇到了错误:

java.io.IOException: Application Default Credentials failed to create the Google App Engine service account credentials

我正在使用库:

<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>${google-api-client.version}</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-compute</artifactId>
<version>${google-api-services-compute.version}</version>
</dependency>

最佳答案

我通过使用 google-api-cient-appengine 而不是 google-api-client 解决了这个问题:

<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-appengine</artifactId>
<version>${google-api-client-appengine.version}</version>
</dependency>

并使用以下方式初始化 GoogleCredential:

GoogleCredential credential = AppEngineCredentialWrapper.getApplicationDefault();

关于java - 应用程序默认凭据无法创建 Google App Engine 服务帐户凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53458174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com