0
votes

I am trying to create a GCS bucket using the JAVA Api from an App Engine project.

I get the following error with not much further information.

403 FORBIDDEN { "code" : 403, "errors" : [ { "domain" : "global", "message" : "Forbidden", "reason" : "forbidden" } ], "message" : "Forbidden" }

Based on reading up on internet, I have already checked the following

Enable Billing - Done.. Enable GoogleCloudStorage API - Done ..

Inspite of doing these, I see the error.

This is how I am creating the storage object ---


httpTransport = GoogleNetHttpTransport.newTrustedTransport();

JSON_FACTORY = JacksonFactory.getDefaultInstance(); 

credential = GoogleCredential.getApplicationDefault();

//Add Scopes
List<String> colls = new ArrayList<String>();

colls.addAll(StorageScopes.all());

if (credential.createScopedRequired()) {
credential = credential.createScoped(colls);
}


//Build storage
storage = new Storage.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName("projectName").build();


Bucket newBucket = storage.buckets().insert("projectName", new Bucket()
                  .setName(bktName).setLocation("US")).execute();

The same code used to work in a different project. However, I am unable to create buckets with a 403 error on a new project that I have created..

Hope to hear something from you guys soon !!!

Thanks,

Srikanth

1
Also tried with AppIdentityCredential.. Still no luck AppIdentityCredential credential = new AppIdentityCredential(Arrays.asList("googleapis.com/auth/devstorage.read_write")); - Srikanth
Have you tried typing projectName in the cloud console manually to see if it's available? Remember bucket names are globally unique. - Nick
Yes, I have tried creating buckets by typing those bucket names in the admin console and it works just fine. However, when I use the JSON API I get this error that hardly contains any further information. - Srikanth

1 Answers

0
votes

Did you enable the Google Cloud Storage JSON API (via the google developers console) for that project?

As a side note, you may want to consider using gcloud-java for storage which should be a better experience on Java.