title: Making an HTTP post request to the Google Play Android Developer API
body: <p>I'm trying to authorize the Google Play Android Developer API. I'm at the step where I need to make an HTTP post request to exchange the authorization code for an access token and a refresh token. <a href="https://developers.google.com/accounts/docs/OAuth2InstalledApp" rel="nofollow">Google</a> gives the following example request:</p>
  
  <pre><code>POST /o/oauth2/token HTTP/1.1
  Host: accounts.google.com
  Content-Type: application/x-www-form-urlencoded
  
  code=4/v6xr77ewYqhvHSyW6UJ1w7jKwAzu&amp;
  client_id=8819981768.apps.googleusercontent.com&amp;
  client_secret={client_secret}&amp;
  redirect_uri=https://oauth2-login-demo.appspot.com/code&amp;
  grant_type=authorization_code
  </code></pre>
  
  <p>I'm confused... First of all, for an installed application (Android) no client_secret is given. I created a web application for the same project in the Google API Console and this gave me a client_secret, so I used that, even though there is no web application. The following code gives me an "invalid_grant" error:</p>
  
  <pre><code>HttpClient httpclient = new DefaultHttpClient();
  HttpPost httppost = new HttpPost("https://accounts.google.com/o/oauth2/token");
  
  try {
      List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(5);
      nameValuePairs.add(new BasicNameValuePair("code", "CODE"));
      nameValuePairs.add(new BasicNameValuePair("client_id", "CLIENT_ID"));
      nameValuePairs.add(new BasicNameValuePair("client_secret", "CLIENT_SECRET"));
      nameValuePairs.add(new BasicNameValuePair("redirect_uri", "urn:ietf:wg:oauth:2.0:oob"));
      nameValuePairs.add(new BasicNameValuePair("grant_type", "authorization_code"));
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
      HttpResponse response = httpclient.execute(httppost);
      ....
  </code></pre>
  
  <p>Taking out the client_secret entirely gave me an "invalid_request" error.</p>