Re: [gs-discussion] Error 403 "Access Not Configured" response in Java while using service account

2,716 views
Skip to first unread message

Nathan Herring (Google Cloud Storage Team)

unread,
Nov 2, 2012, 4:07:08 PM11/2/12
to gs-dis...@googlegroups.com
On Fri, Nov 2, 2012 at 12:19 PM, Eric <eric.w...@gmail.com> wrote:
Hello.

I am trying to access the Cloud Storage API (en route to the Prediction API) from a Java application using a service account.  When I attempt to execute a command, the response contains the following error:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "usageLimits",
    "message" : "Access Not Configured",
    "reason" : "accessNotConfigured"
  } ],
  "message" : "Access Not Configured"
}

Checking these forums and Stack Overflow for other encounters with this issue, the common response seems to be that I simply need to enable Cloud Storage API access in my APIs Console.  Unfortunately, I have already done this.  Since this is the only project with which I am working, there's no chance I have confused the credentials with that of another project either.

That is usually the case. The project related to the client id in the below code snippet would need to have the "Google Cloud Storage JSON API" switch turned on. This is a separate switch from the "Google Cloud Storage" service switch.

The following is the Java code that I've been using, simplified and with confidential constant values obfuscated.  The first block sets up a GoogleCredential object using the service account information, copied from the APIs console.  The second sets up the Storage manager.  The third attempts to create a new bucket, but produces the error.

GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("xxx...@developer.gserviceaccount.com")
.setServiceAccountScopes(StorageScopes.DEVSTORAGE_FULL_CONTROL)
.setServiceAccountPrivateKeyFromP12File(new File("xxxxxxx.p12"))
.build();

Storage storage = new Storage.Builder(HTTP_TRANSPORTJSON_FACTORY, credential)
.setApplicationName("xxxxxxx")
.build();

Bucket bucket = new Bucket();
bucket.setId("test_bucket");
return storage.buckets().insert(bucket).execute();

I normally focus on the front-end of the applications that my team develops, so I'm afraid that I'm overlooking or omitting something simple, in this case.  Any advice would be appreciated.

This looks correct. You will still probably end up with an error as "test_bucket" has already been taken. 

Thank you very much.

--
 
 

Eric

unread,
Nov 2, 2012, 4:28:35 PM11/2/12
to gs-dis...@googlegroups.com
You know, I saw that switch in the APIs Console and considered that as a possibility, but I ignored it since most of the examples that I studied didn't seem to differentiate between the Google Cloud Storage API and the Google Cloud Storage JSON API, despite the handling of JSON that appeared the code.

Thank you very much for your response.  I've submitted a request for access to the JSON API, but in the meantime, I'll start working on a solution that doesn't require it.


On Friday, November 2, 2012 3:19:01 PM UTC-4, Eric wrote:
Hello.

I am trying to access the Cloud Storage API (en route to the Prediction API) from a Java application using a service account.  When I attempt to execute a command, the response contains the following error:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "usageLimits",
    "message" : "Access Not Configured",
    "reason" : "accessNotConfigured"
  } ],
  "message" : "Access Not Configured"
}

Checking these forums and Stack Overflow for other encounters with this issue, the common response seems to be that I simply need to enable Cloud Storage API access in my APIs Console.  Unfortunately, I have already done this.  Since this is the only project with which I am working, there's no chance I have confused the credentials with that of another project either.

The following is the Java code that I've been using, simplified and with confidential constant values obfuscated.  The first block sets up a GoogleCredential object using the service account information, copied from the APIs console.  The second sets up the Storage manager.  The third attempts to create a new bucket, but produces the error.

GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("xxxxxxx@developer.gserviceaccount.com")
.setServiceAccountScopes(StorageScopes.DEVSTORAGE_FULL_CONTROL)
.setServiceAccountPrivateKeyFromP12File(new File("xxxxxxx.p12"))
.build();

Storage storage = new Storage.Builder(HTTP_TRANSPORTJSON_FACTORY, credential)
.setApplicationName("xxxxxxx")
.build();

Bucket bucket = new Bucket();
bucket.setId("test_bucket");
return storage.buckets().insert(bucket).execute();

I normally focus on the front-end of the applications that my team develops, so I'm afraid that I'm overlooking or omitting something simple, in this case.  Any advice would be appreciated.

Thank you very much.

Nathan Herring

unread,
Dec 1, 2012, 8:37:30 PM12/1/12
to gs-dis...@googlegroups.com
On Sat, Dec 1, 2012 at 8:52 AM, sabyasg <sab...@gmail.com> wrote:

Was this issue resolved? I too am facing the same issue. I would like to know how to get past this..


com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "usageLimits",
    "message" : "Access Not Configured",
    "reason" : "accessNotConfigured"
  } ],
  "message" : "Access Not Configured"
}

I did not hear back, so I presume so. This error indicates that the project you are using to authenticate (either by simple API key, or by OAuth2 flow) does not have the Google Cloud Storage JSON API turned on. (Note that it's a separate switch in the APIs Console than Google Cloud Storage, the service.)

--
Nathan Herring | Software Engineer | nher...@google.com | 616-466-4646

Sabyasachi Sengupta

unread,
Dec 1, 2012, 11:53:33 PM12/1/12
to gs-dis...@googlegroups.com
Oh I see, I have requested Google storage team to enable access to it
for our project. Is this documented anywhere (about the JSON Storage
requirement)? Do you know if we can call Java APIs outside GAE?
> --
>
>

Google Cloud Storage Team

unread,
Dec 7, 2012, 11:26:21 AM12/7/12
to gs-dis...@googlegroups.com
Eyal - Looks like you've been sent an invitation. Let me know if you haven't received it.

Sabyasachi - Yes, you can use the Google Cloud Storage JSON API with Java outside of the App Engine environment.

Marc
Google Cloud Storage Team

On Wed, Dec 5, 2012 at 1:59 AM, Eyal Kenigsvain <ey...@cooladata.com> wrote:
Making the request for Google Cloud Storage JSON API is like sending a message in a bottle :)
Anyone know how to expedite the request? I was accepted as trusted tester for a new Google service, the service relies on JSON API and I am stuck.

Ideas welcome.

--
 
 

Sabyasachi Sengupta

unread,
Dec 7, 2012, 11:41:14 AM12/7/12
to gs-dis...@googlegroups.com
Google Storage Team,

Many thanks for the response. I've got another problem for which I
wanted your advise. I am getting "Error 400: Bad request - Required"
error while trying to create a folder from my Java app. Would you
please look at my code below and advise what I am missing? We need
this urgently as our demo is very close. Thanks a lot for the help in
advance,

Regards,
Sabya

public boolean createFolder(Repository repo, String
folderPath) { <<<<< folderPath = sabyasg/CMPE-272
StorageObject so;
String bName, folderName;
Storage s;
StorageObject.Media m;
StorageObject.Owner ow;
Storage.Objects objects;
Storage.Objects.Insert oreq;

bName = FilenameUtils.getFullPath(folderPath);
bName = bName.replaceAll("/$", ""); >>>>> bName = sabyasg
folderName = FilenameUtils.getName(folderPath) +
folderSuffix; >>>>> we thought folderName should be CMPE-272_$folder$
???

m = new StorageObject.Media();
m.setContentType("text/plain");

ow = new StorageObject.Owner();
ow.setEntity("user-" + gsa.selfEntityID);
ow.setEntityId(gsa.selfEntityID);

so = new StorageObject();
so.setBucket(bName);
so.setName(folderName);
so.setMedia(m);
so.setOwner(ow);

s = gsa.setupStorageAccess();
try {
objects = s.objects();
oreq = objects.insert(bName, so);
oreq.execute();
} catch (Exception e) {
System.out.println("Exception " + e + " while
creating object " + bName + "/" + folderName);
return false;
}
return true;
}
[sabyasg@unknown60334b04169e N3Phele]$ clmkdir gstorage:sabyasg/CMPE-272
{bucket=sabyasg, kind=storage#object, media={contentType=text/plain},
name=CMPE-272_$folder$,
owner={entity=user-00b4903a97794542a9b43af017abeddfd22ab2356b3c6fdf90ba19cfc702b305,
entityId=00b4903a97794542a9b43af017abeddfd22ab2356b3c6fdf90ba19cfc702b305}}
Exception com.google.api.client.googleapis.json.GoogleJsonResponseException:
400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Required",
"reason" : "required"
}, {
"domain" : "global",
"message" : "Required",
"reason" : "required"
} ],
"message" : "Required"
} while creating object sabyasg/CMPE-272_$folder$
Failed to create folder
> --
>
>

Joshua

unread,
Dec 7, 2012, 11:53:50 AM12/7/12
to gs-dis...@googlegroups.com
Hi Sabyasachi,

According to the API spec media.data is required, so I would suspect you need to call m.setData(new byte[]).  (Not certain that is the correct data type, but you get the idea).

Josh

On Fri, Dec 7, 2012 at 8:41 AM, Sabyasachi Sengupta <sab...@gmail.com> wrote:
)

Nathan Herring (Google Cloud Storage Team)

unread,
Dec 20, 2012, 3:08:03 PM12/20/12
to gs-dis...@googlegroups.com
You can insert small data using a manually created media data -- you'd need to have the value of media.data be in URL-safe base64 encoding. However, it's a better option for larger files to use the media uploader version of insert(), as in the example.


On Fri, Dec 7, 2012 at 8:41 AM, Sabyasachi Sengupta <sab...@gmail.com> wrote:
--



Reply all
Reply to author
Forward
0 new messages