title: Android App: Acquire Access Token for Google Drive API
body: <p>I am writing an Android (version ICS) app. which uploads data to the Google Drive. The app
  uses oauth2 to acquire the access token. </p>
  
  <p>First step: acquire authorization token.</p>
  
  <pre><code>    String AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/drive";
      // Step 1
      accountManager.getAuthToken(
          account,                                // Account retrieved using getAccountsByType("com.google")
          AUTH_TOKEN_TYPE,                        // Auth Token Type
          options,                                // Authenticator-specific options
          this,                                   // Your activity
          new OnTokenAcquired(),                  // Callback called when a token is successfully acquired
          new Handler(new OnAuthTokenError()));   // Callback called if an error occurs
  }
  private class OnTokenAcquired implements AccountManagerCallback&lt;Bundle&gt; {
      @Override
      public void run(AccountManagerFuture&lt;Bundle&gt; result) {
          // Get the result of the operation from the AccountManagerFuture.
          Bundle bundle;
          try {
              bundle = result.getResult();
  
              authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
  
              Log.d(TAG,"authToken:" + authToken);
  
              exchangeToken access = (exchangeToken) new exchangeToken().execute();
  
          } catch (OperationCanceledException e) {
              e.printStackTrace();
          } catch (AuthenticatorException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  } 
  </code></pre>
  
  <p>Success. An authorization token is acquired.</p>
  
  <p>Step 2: Exchange authorization token for Access Token.</p>
  
  <pre><code>    private class exchangeToken extends AsyncTask&lt;String, Void, Void&gt; {
  
      @Override
      protected Void doInBackground(String... params) {
          HttpTransport transport = new NetHttpTransport();
          JsonFactory jsonFactory = new GsonFactory();
          String CLIENT_ID = "999999999999.apps.googleusercontent.com";
          String CLIENT_SECRET = "axXXXXXXXXXXXXXXX7";
  
          try { // Step 2: Exchange for an access and refresh token
              GoogleTokenResponse authResponse = new GoogleAuthorizationCodeTokenRequest(transport, jsonFactory, CLIENT_ID, CLIENT_SECRET, authToken, CALLBACK_URL).execute();
              accessToken = authResponse.getAccessToken();
              Log.d("Get Access","Token:" + accessToken);
          } catch (IOException e) {
              e.printStackTrace();
          }
          return null;
      }
  }  
  </code></pre>
  
  <p>Fail. The LogCat shows the following:
  com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request</p>
  
  <p>{</p>
  
  <pre><code> "error":"unauthorized_client"
  </code></pre>
  
  <p>}</p>
  
  <p>I have been able to access "Google Drive" on my Android tablet using the "Drive" app. so
  my email account is valid. May be the AUTH_TOKEN_TYPE is incorrect, but the Google Drive
  SDK is not clear what it must be. What am I missing?</p>