4

I'm trying to get familiar with the Google Drive API using the official Java sample. However, after wasting a few hours and attempting to set the sample up two times, I'm still not able to use it as expected.

Instead of displaying a file's content it throws a 404 error in the FileServlet (/svc path). More specifically, service.files().get(fileId).execute(); seems to return null. I've tried it with different files, different MIME types, directly from Google Drive as well as using the Google File Picker.

I've followed the steps described over at https://developers.google.com/drive/examples/java as closely as possible.

Has anyone been able to get the sample running?

edit: Here's the log output of the FileServlet when requesting the URL /svc?file_id=0B08R9MrOE-ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw (the 404 error is thrown at line 78):

2012-04-26 08:21:36.077
com.google.api.client.http.HttpRequest execute: -------------- REQUEST  --------------
GET https://www.googleapis.com/drive/v1/files/0B08R9MrOE-ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw
Accept-Encoding: gzip
User-Agent: Google-HTTP-Java-Client/1.8.3-beta (gzip)

D 2012-04-26 08:21:36.263
com.google.api.client.http.HttpResponse <init>: -------------- RESPONSE --------------
403 OK
content-type: application/json; charset=UTF-8
content-encoding: gzip
date: Thu
date: 26 Apr 2012 06:21:36 GMT
expires: Thu
expires: 26 Apr 2012 06:21:36 GMT
cache-control: private
cache-control: max-age=0
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
content-length: 188
server: GSE
x-google-cache-control: remote-fetch
via: HTTP/1.1 GWA

D 2012-04-26 08:21:36.265
com.google.api.client.http.HttpResponse getContent: Response size: 188 bytes
D 2012-04-26 08:21:36.271
com.google.api.client.http.HttpResponse getContent: {
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit Exceeded. Please sign up",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit Exceeded. Please sign up"
 }
}

This sounds a lot like "I don't know you" to me, so I have taken another look at my Client ID and Client Secret: I've noticed that there are two Client IDs and Client Secrets being displayed in the API Console, one "Client ID for web applications" and another "Client ID for Drive SDK". I've used the one for web applications previously, so I tried to switch to the one for the Drive SDK. Unfortunately, this doesn't change anything. Same error... :/

3
  • 3
    Can you change the logging.properties to log more details on API requests and show us the response body?
    – Alain
    Apr 25, 2012 at 21:46
  • 1
    FWIW, I wrote that sample and its guide. Can you give me an exact line number that is yielding the 404? What URL is being requested against /svc? GET /svc requires the file_id parameter.
    – Vic Fryzel
    Apr 26, 2012 at 4:58
  • @VicFryzel, thanks guys! I've updated the post with log output.
    – TomTasche
    Apr 26, 2012 at 6:35

4 Answers 4

7

As per your logs it seems that your 404 error is caused by a 403 error returned on the request to the Drive API.

Errors from Google APIs usually contains an explanations in their body. In your case:

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

This one would typically mean that you have not enabled access to the Google Drive API on your Google APIs Console project. In order to do this:

  • Open your project in the Google APIs Console
  • Go to the Services section
  • Enable the Drive SDK and Drive API by clicking the On/Off toggle
  • Don't forget to configure your app in the Drive SDK section and your OAuth settings in the **API Access" section

This is all described in the Get started > Register an App section of our documentation. You should also make sure that you go through the other sub-sections of Get started.

10
  • Well, the FileServlet throws a 404 error, but you're right, the actual problem is Google throwing a 403 error. I thought the instructions for the sample included all the necessary steps, but I'll take a look at the docs you suggested. Thanks!
    – TomTasche
    Apr 26, 2012 at 13:38
  • Ok, I've taken a look at the suggested docs, but they are the same I've already skipped through. In my API Console, the status for Drive SDK and Drive API is green, everything in the "Drive SDK" tab has been configured properly (MIME types, "Client ID for Drive SDK", URL, all three scopes), the app has been installed via the Chrome Web Store and the "Client ID for Drive SDK" has been configured in client_secrets.json. I'm clueless.
    – TomTasche
    Apr 26, 2012 at 13:50
  • Have you actually exceeded your default quota of 10,000 queries per day?
    – Vic Fryzel
    Apr 26, 2012 at 15:08
  • You should use the client ID and secret listed under API Access.
    – Vic Fryzel
    Apr 26, 2012 at 15:16
  • @VicFryzel there are two Client IDs listed under API Access: "Client ID for web applications" and "Client ID for Drive SDK". I strongly doubt that I did exceed my quota. ;) I'm the only user...
    – TomTasche
    Apr 27, 2012 at 7:59
1

I eventually managed to get it working. I'm not sure what was the problem before, but here are some tips for those who are facing similar problems:

  • The "Client ID for web applications" and the "Client ID for Drive SDK" confused me. Unfortunately the documentation doesn't tell you which one to use at which place, but it seems like you only need the "Client ID for web applications".

  • If you update your Chrome extension or the API console it could take some time until Drive recognizes those changes. For example, changing the OAuth Client ID in the API console could take some time until it takes effect, since everybody's caching. If you are testing your application, deleting cache and cookies helps speed up the process.

Good luck with your applications, and thanks to everybody who helped me!

1

In my experience, "403 Quota Exceeded" always stems from the HTPP Authorization header not being set.

1

I used the java OAuth code distributed in Google's dredit sample for a program that goes through the "opens with" flow and likewise recieved the 403 error.

I had to dig into the OAuth code to find the problem, the source of which I haven't seen mentioned elsewhere in regard to the 403 error. Essentially the ExchangeCode method of CredentialMediator assumes there is only one redirect uri and this is the one you are hoping to go to. This wasn't the case for me and resulted in a CodeExchangeException.

To resolve you could massage the list of uris in the client_secrets so the uri you wish to redirect to is first or some such, but if this method could go to any one of a number of uris it will need parameterisation.

I hope this helps someone root out their 403 gremlin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.