OAuth and Drive API, can't fetch files

2,167 views
Skip to first unread message

Mikko Tanskanen

unread,
Feb 20, 2013, 2:20:34 AM2/20/13
to oauth...@googlegroups.com
Hi all,

I have a web application that needs to list all files from my Google Drive and then fetch them when clicked.
I use OAuth for authenticating and it seems to work (the same code works well with Calendar API)

Basically it is:

credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
                            .setJsonFactory(JSON_FACTORY)
                            .setServiceAccountId(apiEmail)
                            .setServiceAccountScopes(DriveScopes.DRIVE)
                            .setServiceAccountPrivateKeyFromP12File(p12File)
                            .build();
                   
                    credential.refreshToken();
                   
                    service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
                            .setApplicationName("My API")
                            .build();

After that I try:

FileList files = service.files().list().execute();

The returned FileList is:

{"etag":"\"_U9FTLXcHskmKgrWAZqJlfW8kCo/vyGp6PvFo4RvsFtPoIWeCReyIC8\"","items":[],"kind":"drive#fileList","selfLink":"https://www.googleapis.com/drive/v2/files"}
 
If I check that selfLink the contents is:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}

Daily limit is not an issue here.

When downloading a file this is performed:

File file = service.files().get(fileId).execute();

And it produces this (fileId exists):

An error occured: com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
  "code" : 404,
  "errors" : [ {
    "domain" : "global",
    "message" : "File not found: 0B97KF40kTwrTaTllMnZCTV9ZSnM",
    "reason" : "notFound"
  } ],
  "message" : "File not found: 0B97KF40kTwrTaTllMnZCTV9ZSnM"
}

And again when checking https://www.googleapis.com/drive/v2/files/0B97KF40kTwrTaTllMnZCTV9ZSnM the same "dailyLimitExceededUnreg" is seen.

What is going on here, is there a problem in my authentication?

Mikko Tanskanen

unread,
Feb 20, 2013, 3:02:53 AM2/20/13
to oauth...@googlegroups.com
I use OAuth2 (of course) and not OAuth. And I should add, that accessToken in credential is null before refreshToken() method call. I have enabled Drive and Drive SDK in Console. Should I configure Drive Integration in Drive SDK somehow? From Googles documentation I have understood that it's not necessary and the methods I'm using should work without further configuring.

Mikko Tanskanen

unread,
Feb 20, 2013, 7:10:35 AM2/20/13
to oauth...@googlegroups.com

It seems that the file I tried to download was not shared with dev account (it was not uploaded via API) and thus I couldn't download it via API.

File list started working when I changed constructor of service as:

service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, null)
                        .setHttpRequestInitializer(credential)
                        .setApplicationName("My API")
                        .build();

Naveen Agarwal

unread,
Feb 21, 2013, 9:26:22 PM2/21/13
to oauth...@googlegroups.com

Glad to see you were able to get this resolved.

Thanks

Naveen

--
You received this message because you are subscribed to the Google Groups "Developer Forum for Google API Access using OAuth2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to oauth2-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages