Access to Google Cloud Storage using java library gets '403 Forbidden'

I'm trying to use the scala java cloud storage java library 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 

however i got

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

My email account has access to the bucket, I can access it with gsutil by creating a project in my account. I created xxx@developer.gserviceaccount.com in the project in my account, as well as any idea on how I can set permission?

+6
source share
2 answers

Just came up with the same problem and thought we found a solution. To fix this, the owner of the Google Play Developer Console we were aiming for had to add our support email address to the Google Play console permissions list and grant privileges to the Financial Reporting service account.

+3
source

If you are doing this from an instance of Google Compute Engine, make sure you run this instance with permissions allowed for service accounts ... see https://cloud.google.com/compute/docs/authentication#using

If you do not start the instance with the service account, it will not have permissions to use it.

0
source

Source: https://habr.com/ru/post/975072/


All Articles