Google Drive SDK - Java sample not working

I'm trying to familiarize myself with the Google Drive API using the official Java sample. However, after spending several hours trying to install the sample twice, I still cannot use it as expected.

Instead of displaying the contents of the file, it throws a 404 error in the FileServlet (path / svc). In particular, service.files().get(fileId).execute(); seems to return null. I tried it with different files, different MIME types, directly from Google Drive, and also using File File Picker.

I followed the steps as described in https://developers.google.com/drive/examples/java as close as possible.

Has anyone been able to get a sample?

change Here the output of the FileServlet log when requesting URL /svc?file_id=0B08R9MrOE-ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw (error 404 is selected on 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" } } 

It sounds just like “I don't know you,” so I looked again at my client identifier and client secrets: I noticed that the identifier has two client identifiers and client API secrets, one “Client identifier for web applications” and another "Client ID for the SDK drive." I previously used one for web applications, so I tried switching to one for the SDK drive. Unfortunately, this does not change anything. Same error ...: /

+4
source share
4 answers

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

  • The client identifier for web applications and the client identifier for the SDK drive confused me. Unfortunately, the documentation does not indicate which one should be used in which place, but it looks like you only need the "Client Identifier for Web Applications".

  • If you upgrade the Chrome extension or API console, it may take some time until the drive recognizes these changes. For example, changing the OAuth client ID in the API console may take some time until it takes effect, as everyone is cached. If you are testing your application, removing cache and cookies helps speed up the process.

Good luck in your applications and thanks to everyone who helped me!

+1
source

According to your logs, it seems that your 404 error is caused by the 403 error returned in the request to the API.

Google API errors usually contain 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 usually means that you did not enable access to the Google Drive API in the Google API Console project. For this:

  • Open the project in the Google API Console
  • Go to Services
  • Turn on the SDK Driver and API Driver by clicking the On / Off button
  • Remember to configure your application in the SDK section and OAuth settings in the ** Access API section

All of this is described in the Getting Started> Register application section in our documentation. You must also make sure that you go through the other sections of Getting Started .

+7
source

In my experience, "403 Quota Exceeded" is always due to the fact that the HTPP authorization header is not set.

+1
source

I used the Java OAuth code, common in the Google dredit sample for a program that goes through the "opens with" thread, and also got a 403 error.

I needed to delve into OAuth code to find a problem whose source I did not see elsewhere regarding error 403. Basically, the ExchangeCode CredentialMediator method assumes there is only one uri redirect, and this is the one you are hoping for. This was not for me and led to a CodeExchangeException.

To solve the problem, you can massage the uris list in client_secrets, so that the uri you want to redirect is the first or some of them, but if this method can go to any of several uris, it will need parameterization.

I hope this helps someone expel their 403 gremlins.

+1
source

All Articles