title: Google+ api - Key from https://accounts.google.com/o/oauth2/token gives 401 errors
body: <p>I'm having some trouble with Google+ API OAuth2 tokens.</p>
  
  <p>Here is a simple program that gets an OAuth2 access token:</p>
  
  <pre><code>HttpClient httpclient = new HttpClient();
          PostMethod postMethod = new PostMethod("https://accounts.google.com/o/oauth2/token");
          NameValuePair[] data = {
                  new NameValuePair("client_id", "API KEY HERE"),
                  new NameValuePair("redirect_uri", "URL HERE"),
                  new NameValuePair("client_secret", "SECRET HERE"),
                  new NameValuePair("code", "CODE HERE"),
                  new NameValuePair("grant_type", "authorization_code")
          };
          postMethod.setRequestBody(data);
          try {
              int result = httpclient.executeMethod(postMethod);
              assertEquals(result, 200);
              System.out.println("Response body: ");
              System.out.println(postMethod.getResponseBodyAsString());
          } catch (IOException e) {
              e.printStackTrace();
          }
  </code></pre>
  
  <p>This successfully generates an OAuth2 token. Such as: ya29.AHES6ZTZgptKHyZ530MoYVDPaeXvjK5DWQzPqxoNNEL2C7gsQwGfmvfT8Q</p>
  
  <p>Then I set up a simple test program that can test calling the /people API from that token:</p>
  
  <pre><code>@Test
      public void testGoogleAPIAuthdRequest() throws Exception {
          String feedUrl = "https://www.googleapis.com/plus/v1/people/me";
          String apiKey = "MY API KEY";
          String oauthCode = "OAUTH CODE FROM ABOVE";
          String jsonStr = executeGoogleFeed(feedUrl, apiKey, oauthCode).getResponseBodyAsString("UTF-8");
      }
  
      public Response executeGoogleFeed(String feedURL, String apiKey, String oauthCode) throws Exception {
          StringBuilder urlStr = new StringBuilder();
          urlStr.append(feedURL);
          urlStr.append("?key=");
          urlStr.append(apiKey);
          Map&lt;String, String&gt; hashMap = new HashMap&lt;String, String&gt;();
          hashMap.put("Authorization", "Bearer " + oauthCode);
          return HttpUtil.doHttpRequest(urlStr.toString(), MethodType.GET.toString(), null,
                  hashMap);
      }
  </code></pre>
  
  <p>This gives me a 401 error. Permission denied. </p>
  
  <p>When I go to <a href="https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=INSERT_ACCESS_TOKEN" rel="nofollow">https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=INSERT_ACCESS_TOKEN</a>, the Token shows as valid.</p>
  
  <p>Also, when I go to <a href="https://developers.google.com/+/api/latest/people/get" rel="nofollow">https://developers.google.com/+/api/latest/people/get</a> and get the OAuth token from the OAuth2 sign-on feature... and I plug that OAuth token into my JUnit test... it works! </p>
  
  <p>Anyone know why my call to <a href="https://accounts.google.com/o/oauth2/token" rel="nofollow">https://accounts.google.com/o/oauth2/token</a> cannot be used as the Bearer parameter in Google+'s api? </p>