title: Authorization-Heades for Google Data (Calendar) API request
body: <p>I want to be able to retrieve a users calendar and events from the Google Calendar API. Basically I managed to get an Auth-Token from Android's AccountManager and do the request, but I get</p>
  
  <pre><code>  "error": {
      "errors": [
      {
      "domain": "global",
      "reason": "authError",
      "message": "Invalid Credentials",
      "locationType": "header",
      "location": "Authorization"
      }
      ],
      "code": 401,
      "message": "Invalid Credentials"
      }
      }
  </code></pre>
  
  <p>As a response. The code producing it is (partial). When running this for the first time, Android asked me to authorize Access to my calendar data for my app, which I accepted.</p>
  
  <pre><code>    final Account account = manager.getAccountsByType("com.google")[0];
  
      AccountManagerFuture&lt;Bundle&gt; accountManagerFuture =
              manager.getAuthToken(account, "cl", true,
                      new AccountManagerCallback&lt;Bundle&gt;() {
  
                          public void run(AccountManagerFuture&lt;Bundle&gt; future) {
                              try {
                                  Bundle bundle = future.getResult();
  
                                  if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
  
                                      final String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
  
                                      final Uri usersCalendars = Uri.parse(
                                              "https://www.googleapis.com/calendar/v3/users/me/calendarList")
                                              .buildUpon()
                                              .appendQueryParameter("key","--myapikey--")
                                              .build();
  
                                      HttpClient client = new DefaultHttpClient();
  
                                      HttpGet request = new HttpGet(usersCalendars.toString());
  
                                      request.setHeader("Authorization","GoogleLoginAuth=" + authToken);
                                      request.setHeader("GData-Version","3.0");
  
                                      HttpResponse response =  client.execute(request);
  
                                      // outputting response, logging etc
  </code></pre>
  
  <p>As you can see I am not using the google-api-java-client, because I could not get that one to fly either. Basically the example code calls methods that do not exist anymore / are moved to Android's AccountManager and the android-calendar-example produced a 401 eror instead of listing my calendars.</p>
  
  <p>If you guys have any hints, documentation etc. I'd be glad.</p>
  
  <p><em>edit</em> I just tried invalidating the token via</p>
  
  <pre><code>manager.invalidateAuthToken("com.google",authToken);
  </code></pre>
  
  <p>then retrieving a new one via, with the same result.</p>