使用Java库访问Google云存储获取"403禁止" [英] access google cloud storage using java library gets '403 forbidden'

查看:154
本文介绍了使用Java库访问Google云存储获取"403禁止"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Scala中的Google Cloud Storage Java库列出存储桶中的项目

I'm trying to use google cloud storage java library in scala to list items in a bucket

val credential = new GoogleCredential.Builder()
  .setTransport(GoogleNetHttpTransport.newTrustedTransport())
  .setJsonFactory(JacksonFactory.getDefaultInstance())
  .setServiceAccountId("xxx@developer.gserviceaccount.com")
  .setServiceAccountScopes(Collections.singleton(StorageScopes.DEVSTORAGE_READ_ONLY))
  .setServiceAccountPrivateKeyFromP12File(new File("file.p12"))
  .build()
val storage = new Storage.Builder(
  GoogleNetHttpTransport.newTrustedTransport(),
  JacksonFactory.getDefaultInstance(),
  credential)
  .setHttpRequestInitializer(credential)
  .setApplicationName("app")
  .build()
storage.objects.list("bucket").execute

但是我得到了

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Forbidden",
    "reason" : "forbidden"
  } ],
  "message" : "Forbidden"
}

我的电子邮件帐户可以访问该存储桶,我也可以通过在我的帐户中创建一个项目来使用gsutil对其进行访问. 我也已经在我帐户中的项目中创建了xxx@developer.gserviceaccount.com,知道如何设置权限?

my email account have the access to the bucket, I can access it using gsutil by creating a project in my account as well. I've created xxx@developer.gserviceaccount.com in a project in my account as well, any idea that how can I set the permission?

推荐答案

只是遇到了同样的问题,并认为我们已经找到了解决方案.要解决此问题,我们尝试访问的Google Play开发者控制台的所有者必须将我们的服务帐户电子邮件地址添加到Google Play控制台权限列表中,并赋予该服务帐户财务报告"特权.

Just been coming up against the same issue, and think we've found the solution. To fix it, the owner of the Google Play Developer Console that we were trying to access had to add our service account email address to the Google Play Console permissions list, and give the service account Financial Reports privileges.

这篇关于使用Java库访问Google云存储获取"403禁止"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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