Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle drive SDK 2.0 throws error 400 Bad Request
    text
    copied!<p>I've been fighting with Google Drive API for Android for more than 50 hours now, and have not come one inch closer. From my understanding, there are 1001 ways to access Google drive (Google Docs API, REST &amp; Google Drive SDK v2). I'm using Google Drive SDK v2. I want want to access Google Drive to upload jpeg files. Platform, Android 2.2+.</p> <p>What I've tried:</p> <ul> <li><p>Using the recently released SDK: <a href="http://code.google.com/p/google-api-java-client/wiki/APIs#Drive_API" rel="nofollow">http://code.google.com/p/google-api-java-client/wiki/APIs#Drive_API</a></p></li> <li><p>I've watched the Google I/O sesssion, but the most important part (how to create a Drive object using your Client ID &amp; Client Secret) was left out: <a href="https://developers.google.com/events/io/sessions/gooio2012/705/" rel="nofollow">https://developers.google.com/events/io/sessions/gooio2012/705/</a></p></li> <li><p>I have created multiple keys on <a href="https://code.google.com/apis/console" rel="nofollow">https://code.google.com/apis/console</a>. The last one I've created (and tested with) was created using "Create another client ID..." -> "Installed Application" -> "Android". I've used the key in the ~/.android/debug.keystore.</p></li> <li><p>I've also tried to create a key for an "Other" (instead of Android/iOS) installed app, but this gives me a Client ID and Client secret. It seems like the Drive object does not accept a client secret.</p></li> <li><p>Where the code says "1234567890-abcdefghij123klmnop.apps.googleusercontent.com", I've tried to use both "API key" and the "Client ID", both gave the same error.</p></li> </ul> <p>My code:</p> <pre><code>Account account = AccountManager.get(context).getAccountsByType( "com.google")[0]; String token; try { token = GoogleAuthUtil.getToken(context, account.name, "oauth2:" + DriveScopes.DRIVE_FILE); } catch (UserRecoverableAuthException e) { context.startActivityForResult(e.getIntent(), ASK_PERMISSION); return; } catch (IOException e) { return; } catch (GoogleAuthException e) { return; } HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); Drive.Builder b = new Drive.Builder(httpTransport, jsonFactory, null); final String tokenCopy = token; b.setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() { public void initialize(JsonHttpRequest request) throws IOException { DriveRequest driveRequest = (DriveRequest) request; driveRequest.setPrettyPrint(true); driveRequest .setKey("1234567890-abcdefghij123klmnop.apps.googleusercontent.com"); driveRequest.setOauthToken(tokenCopy); } }); final Drive drive = b.build(); FileList files; try { files = drive.files().list().setQ("mimeType=text/plain").execute(); } catch (IOException e) { e.printStackTrace(); // throws HTTP 400 } </code></pre> <p>The error I'm getting is:</p> <pre><code>com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request { "code" : 400, "errors" : [ { "domain" : "global", "location" : "q", "locationType" : "parameter", "message" : "Invalid Value", "reason" : "invalid" } ], "message" : "Invalid Value" } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload