gpt4 book ai didi

java - 设置 GOOGLE_APPLICATION_CREDENTIALS 仍然无法启用对 Google Storage 的访问

转载 作者:行者123 更新时间:2023-11-30 06:15:58 24 4
gpt4 key购买 nike

This answer展示如何使用 Java 中的服务帐户访问 Google Cloud Storage。
使用硬编码服务帐户凭据,我可以访问 GCS。但是,使用 GOOGLE_APPLICATION_CREDENTIALS 或运行 gcloud auth application-default login,我无法访问 GCS 并收到 GoogleJsonResponseException: 401 Unauthorized
我的操作系统是Win7_64x。

Exception in thread "main" com.google.cloud.storage.StorageException: Anonymous caller does not have storage.objects.get access to nmjcloud_jar_test/addons/simple-bean-1.0.jar.
at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:191)
at com.google.cloud.storage.spi.v1.HttpStorageRpc.get(HttpStorageRpc.java:342)
at com.google.cloud.storage.StorageImpl$5.call(StorageImpl.java:198)
at com.google.cloud.storage.StorageImpl$5.call(StorageImpl.java:195)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:89)
at com.google.cloud.RetryHelper.run(RetryHelper.java:74)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:51)
at com.google.cloud.storage.StorageImpl.get(StorageImpl.java:195)
at com.google.cloud.storage.StorageImpl.get(StorageImpl.java:209)
at com.example.storage.QuickstartSample.main(QuickstartSample.java:47)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Anonymous caller does not have storage.objects.get access to nmjcloud_jar_test/addons/simple-bean-1.0.jar.",
"reason" : "required"
} ],
"message" : "Anonymous caller does not have storage.objects.get access to nmjcloud_jar_test/addons/simple-bean-1.0.jar."
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.google.cloud.storage.spi.v1.HttpStorageRpc.get(HttpStorageRpc.java:340)
... 8 more

如何检查我哪里错了?

最佳答案

哦,亲爱的。我犯了一个错误。

我在变量值文本框中引用了变量值。
不需要使用引号将该字符串括起来。

不正确:“/path/to/jsonfile.json”
正确:/path/to/jsonfile.json

关于java - 设置 GOOGLE_APPLICATION_CREDENTIALS 仍然无法启用对 Google Storage 的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49186416/

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