title: Google Drive Returning Error 400 or 403 to my Android App?
body: <p>Here's my code for requesting the auth token...</p>
  
  <pre><code>AccountManager am = AccountManager.get(this);
  Bundle options = new Bundle();
  am.getAuthToken(
      (am.getAccounts())[0], // My test device only has one account. I'll add a picker before releasing this app.
      "oauth2:" + DriveScopes.DRIVE,
      options,
      true, // I've tried both true and false... doesn't seem to change anything?
      new OnTokenAcquired(),
      null); // I used to have a handler, but it absolutely never got called.
  </code></pre>
  
  <p>Here's the code that handles the token:</p>
  
  <pre><code>private class OnTokenAcquired implements AccountManagerCallback&lt;Bundle&gt; {
      @Override
      public void run(AccountManagerFuture&lt;Bundle&gt; result) {
          String token = result.getResult().getString(AccountManager.KEY_AUTHTOKEN);
  
          HttpTransport httpTransport = new NetHttpTransport();
          JacksonFactory jsonFactory = new JacksonFactory();
  
          Drive.Builder b = new Drive.Builder(httpTransport, jsonFactory, null);
          b.setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {
              @Override
              public void initialize(JsonHttpRequest request) throws IOException {
                  DriveRequest driveRequest = (DriveRequest) request;
                  driveRequest.setPrettyPrint(true);
                  driveRequest.setKey("xxxxxxxxxxxx.apps.googleusercontent.com"); // I replaced the number with x's. I'll explain where I got the number from below.
                  driveRequest.setOauthToken(token);
              }
          });
  
          final Drive drive = b.build();
  
          final com.google.api.services.drive.model.File body = new com.google.api.services.drive.model.File();
          body.setTitle("My document");
          body.setDescription("A test document");
          body.setMimeType("text/plain");
  
          java.io.File fileContent = new java.io.File("document.txt");
          final FileContent mediaContent = new FileContent("text/plain", fileContent);
  
          new Thread(new Runnable() {
              public void run() {
                  com.google.api.services.drive.model.File file;
                  try {
                      file = drive.files().insert(body, mediaContent).execute();
                      Log.i("Hi", "File ID: " + file.getId());
                  } catch (IOException e) {
                      Log.i("Hi", "The upload/insert was caught, which suggests it wasn't successful...");
                      e.printStackTrace();
                      AccountManager am = AccountManager.get(activity);
                      am.invalidateAuthToken(am.getAccounts()[0].type, null);
                      Bundle options = new Bundle();
                      am.getAuthToken(
                          (am.getAccounts())[0],
                          "oauth2:" + DriveScopes.DRIVE,
                          options,
                          true,
                          new OnTokenAcquired(),
                          null);
                      }
                  }
              }).start();
          Intent launch = (Intent)result.getResult().get(AccountManager.KEY_INTENT);
          if (launch != null) {
              Log.i("Hi", "Something came back as a KEY_INTENT");
              startActivityForResult(launch, 3025);
              return;
          } else {
              Log.i("Hi", "I checked, but there was nothing for KEY_INTENT.");
          }
      }
  }
  </code></pre>
  
  <p>I have implemented onActivityResult and have it set up to log the requestCode and resultCode if it's ever invoked, but it never is. Were it to ever be invoked, it just fires off another token request if the requestCode is 3025 and the resultCode is RESULT_OK.</p>
  
  <p>Here's how I got my clientID:</p>
  
  <ul>
  <li>I went to Google APIs console or whatever it's called.</li>
  <li>I made a new product.</li>
  <li>I enabled and set up the Drive SDK (sort of... I'm not making a web app, so I just pointed the URL at a website I own.)</li>
  <li>Under "API Access" I clicked "Create another client ID..." and set it up for an installed Android app. (The fingerprint may not be quite right? Would that cause the error?)</li>
  <li>I copied the Client ID listed under Client ID for Installed Applications (not the one from Client ID for Drive SDK).</li>
  </ul>
  
  <p>As it is, here's what I get from the log:</p>
  
  <pre><code>I checked, but there was nothing for KEY_INTENT // My log message.
  The upload/insert was caught, which suggests it didn't work... // Another one of my log messages.
  com.google.api.client.http.HttpResponseException: 400 Bad Request
  {
   "error": {
    "errors": [
     {
      "domain": "usageLimits",
      "reason": "keyInvalid",
      "message": "Bad Request"
     }
    ],
    "code": 400,
    "message": "Bad Request"
   }
  }
  </code></pre>
  
  <p>Followed by a more ordinary stack trace... </p>
  
  <p><strong>EDIT</strong>
  Recently it stopped giving me 400 and instead started giving me 403 Forbidden, still with the domain of usageLimits, reason now being accessNotConfigured and message being Access Not Figured.</p>