代码之家  ›  专栏  ›  技术社区  ›  Omarkad

应用程序默认凭据无法创建Google应用程序引擎服务帐户凭据

  •  1
  • Omarkad  · 技术社区  · 6 年前

    我正在开发一个应用程序,它使用部署在AppEngine上的REST端点启动GoogleVM实例。

    初始化计算引擎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>
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Omarkad    6 年前

    我用 谷歌应用程序接口 而不是 谷歌API客户端 :

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

    并初始化 谷歌凭证 使用:

    GoogleCredential credential = AppEngineCredentialWrapper.getApplicationDefault();