I’m trying to write an AppEngine application that writes a Google document to Google Drive, places it in a specific set of folders and sets permissions. I have work with the old DocsList API, but since this is just deprecated, I decided to update my code (and I had some additional functions to add anyway).
The problem I am facing is this: when I use a service account and try to impersonate a specific user, I get 403 with usage restrictions, although I have not used any of my quotas.
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(" user@xxxxxx.org ").build();
I than use these credentials to initialize 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 tried using a new disk (....), but it just won’t work, no matter what. Saves errors in that no internal methods were found!
Back to this problem: When I use "d" to call something like .files (). Get ("SOMEFILEID"). Execute () I get 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 understand why this is not working. I watch online all day, but cannot find a suitable answer. Some help is much appreciated.