设置GOOGLE_APPLICATION_CREDENTIALS仍然无法启用对Google存储空间的访问 [英] Setting GOOGLE_APPLICATION_CREDENTIALS still doesn't enable the access to Google Storage

查看:517
本文介绍了设置GOOGLE_APPLICATION_CREDENTIALS仍然无法启用对Google存储空间的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此答案显示了如何使用Java中的服务帐户访问Google Cloud Storage.
使用硬编码服务帐户凭据,我可以访问GCS. 但是,使用GOOGLE_APPLICATION_CREDENTIALS或运行gcloud auth application-default login,我无法访问GCS并获得GoogleJsonResponseException: 401 Unauthorized.
我的操作系统是Win7_64x.

This answer shows how to access Google Cloud Storage with a service account in Java.
Using hard-coded Service Account Credentials, I could access GCS. However, using GOOGLE_APPLICATION_CREDENTIALS or running gcloud auth application-default login, I couldn't access GCS and got GoogleJsonResponseException: 401 Unauthorized.
My OS is 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

如何检查我哪里错了?

推荐答案

哦,亲爱的.我弄错了.

Oh dear. I made a mistake.

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

I quoted up the variable value in the textbox of variable value.
Do not need to use quotation marks to enclose that string.

错误:"/path/to/jsonfile.json"
正确:/path/to/jsonfile.json

Incorrect: "/path/to/jsonfile.json"
Correct: /path/to/jsonfile.json

这篇关于设置GOOGLE_APPLICATION_CREDENTIALS仍然无法启用对Google存储空间的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆