title: Reproducing code from Calendar API Explorer in Java
body: <p>I'm playing with the API explorer: <a href="http://developers.google.com/apis-explorer/#p/calendar/v3/calendar.calendarList.list" rel="nofollow">http://developers.google.com/apis-explorer/#p/calendar/v3/calendar.calendarList.list</a>  </p>
  
  <p>I can get that work, (after authenticating with OAuth). The request looks something like this:</p>
  
  <p>GET <a href="https://www.googleapis.com/calendar/v3/users/me/calendarList?fields=items(description%2Ckind%2Csummary)&amp;key=" rel="nofollow">https://www.googleapis.com/calendar/v3/users/me/calendarList?fields=items(description%2Ckind%2Csummary)&amp;key=</a>{YOUR_API_KEY}</p>
  
  <p>Authorization:<code>Bearer ya29.1.FGDtN_WzfD1qNt86qJJlIwR65hdr1sU6BYqndDRPgyMF5xVK2olOacitZH41hQ</code><br>
  X-JavaScript-User-Agent: <code>Google APIs Explorer</code></p>
  
  <p>I'm trying to reproduce that using Jersey (keys and stuff have been changed):</p>
  
  <pre><code>String apikey = "blah-blah-e2GB-yZp7CasdfoC8Bm10ZDhCpk";
  String getCals = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
  
  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(getCals);
  target = target.queryParam("fields", "items(description%2Cid%2Ckind%2Csummary)");
  target = target.queryParam("key", apikey);
  
  
  Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON_TYPE);
  builder.header("Authorization:", "Bearer ya29.1.AADtN_WzfDabsdwerwer0d0f0ndDRPgyMF5xVK2olOacitZH41hQ");
  Response response = builder.get();
  int status = response.getStatus();
  String ret = response.readEntity(String.class);
  log.debug("status: " + status + " response:\n" + ret);
  </code></pre>
  
  <p>Unfortunately that doesn't work - I get this back:</p>
  
  <pre><code>jerseyTest App - status: 401 response:
  {
   "error": {
    "errors": [
     {
      "domain": "global",
      "reason": "authError",
      "message": "Invalid Credentials",
      "locationType": "header",
      "location": "Authorization"
     }
    ],
    "code": 401,
    "message": "Invalid Credentials"
   }
  }
  </code></pre>
  
  <p>Can anyone see why?</p>