我正在尝试在java中使用谷歌视觉库。这些步骤指定我需要设置我的身份验证凭据才能开始使用this https://developers.google.com/identity/protocols/application-default-credentials图书馆 。我能够从 API 控制台凭据页面生成 json 属性文件,并将其放置在资源文件夹中的 Spring Boot 应用程序中。
我认为更新了我的 application.properties 文件以包含如下值:
GOOGLE_APPLICATION_CREDENTIALS=datg-avatar-generator-9dc9155cd5bd.json
我还在我的控制器中设置我的属性源,如下所示:
@PropertySource("${GOOGLE_APPLICATION_CREDENTIALS}")
但是,执行此操作后,我仍然收到错误消息:
java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
我能够使用 Spring Cloud GCP spring-cloud-gcp-starter-data-datastore 配置此属性,创建服务帐户项目所有者,将 JSON 私钥复制到主资源目录,并在应用程序中设置以下属性。特性
spring.cloud.gcp.project-id=<project-id>
spring.cloud.gcp.credentials.location=classpath:<credentials-private-key>.json
来自文档 https://docs.spring.io/spring-cloud-gcp/docs/1.1.0.M1/reference/html/spring-cloud-gcp-core.html
您可以通过访问此页面找到项目 IDhttps://support.google.com/googleapi/answer/7014113?hl=en https://support.google.com/googleapi/answer/7014113?hl=en转到 API 控制台。
从项目列表中,选择管理所有项目。将显示您所属的所有项目的名称和 ID。
您还可以选择项目进入设置并查看项目 ID
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)