Stefan Hogendoorn
Stefan Hogendoorn

Reputation: 213

Google Drive service account returns 403 usageLimits

I'm trying to write an AppEngine app that writes a Google Document to Google Drive, puts in a specific set of folders and sets access rights. I have this working with the old DocsList API but since that just got deprecated I decided to update my code (and I had some additional functions to add anyway).

Problem I'm facing is this: When I use a service account and try to impersonate a specific user I get a 403 with usageLimits even though I have not used up any of my quota.

Here is the code I'm using:

GoogleCredential credentials = new GoogleCredential.Builder()
                 .setTransport(HTTP_TRANSPORT)
                 .setJsonFactory(JSON_FACTORY)
                 .setServiceAccountId("xxxxxxxxxxgserviceaccount.com")
                 .setServiceAccountScopes(DriveScopes.DRIVE)
                 .setServiceAccountPrivateKeyFromP12File(
                                    new java.io.File("xxxx-privatekey.p12"))
                 .setServiceAccountUser("[email protected]").build();

I than use these credentials to initiate my Drive object:

Drive d = Drive.builder(httpTransport, jsonFactory)
               .setHttpRequestInitializer(credentials)
               .setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {
                @Override
                public void initialize(JsonHttpRequest request) {
                    DriveRequest driveRequest = (DriveRequest) request;
                    driveRequest.setPrettyPrint(true);
                }
            }).setApplicationName("MYAPPNAME").build();

BTW: I've tried using new Drive(....) but that just won't work, no matter what I try. Keeps throwing errors that internal methods are not found!

Back to this issue: When I than use 'd' to call something like .files().get("SOMEFILEID").execute() I get a 403

{ "code" : 403,
"errors" : [ {
    "domain" : "usageLimits",
    "message" : "Daily Limit Exceeded. Please sign up",
    "reason" : "dailyLimitExceededUnreg",
    "extendedHelp" : "https://code.google.com/apis/console"
  } ],
  "message" : "Daily Limit Exceeded. Please sign up"
}

I can't figure out why this doesn't work. I've look online all day but can't find a suitable answer. Some help is very much appreciated.

Upvotes: 4

Views: 4439

Answers (2)

Stefan Hogendoorn
Stefan Hogendoorn

Reputation: 213

So pinoyyid's answer did help, although it wasn't the definitive answer.

I ended up solving it like this:

I took my AppID (xxxxx.apps.googleusercontent.com) and added it to my CPanel https://www.google.com/a/cpanel/[[YOURDOMAIN]]/ManageOauthClients with these scopes:

After that I had could do an authenticated request to the Drive environment. Running into a stack of different issues now but the 403 got solved.

Upvotes: 2

pinoyyid
pinoyyid

Reputation: 22296

I usually get a 403 when the API call was missing the Authorization http header. Trace the http and look at the headers. The rationale for the "quota" message is that without an Auth header, you are anonymous, and the quota for anonymous use is zero.

You might also check that your app is registered for both of the Drive APIs, as I've heard that that can cause the same problem.

On the internal method issue, that sounds like you're using incompatible library versions. What worked best for me was to delete all of the libraries I had downloaded with the sample code, then use the Google Eclipse plugin to "Google/Add Google APIs..." to download all of the latest versions.

Upvotes: 1

Related Questions