title: Missing parameter access_token on OAuth2 request
body: <p>I'm using the Apache Amber libraries to try to retrieve an OAuth2 access token from a Web site under my control. My client code is running under Android.</p>
  
  <p>My code is patterned on the example at:</p>
  
  <p><a href="https://cwiki.apache.org/confluence/display/AMBER/OAuth+2.0+Client+Quickstart" rel="nofollow noreferrer">https://cwiki.apache.org/confluence/display/AMBER/OAuth+2.0+Client+Quickstart</a></p>
  
  <p>In the first step, I'm able to retrieve a "code" by submitting a GET request using a WebView browser:</p>
  
  <pre><code>OAuthClientRequest request = OAuthClientRequest
   .authorizationLocation(AUTHORIZE_URL)
   .setClientId(CLIENT_ID)
   .setRedirectURI(REDIR_URL)
   .setResponseType(CODE_RESPONSE)
   .buildQueryMessage();
  
   webview.loadUrl(request.getLocationUri());
  </code></pre>
  
  <p>I use a WebViewClient callback to capture the redirect URL with the "code" parameter. So far, so good.</p>
  
  <p>Using that code, I try to retrieve my access token:</p>
  
  <pre><code>OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
  
  OAuthClientRequest request = OAuthClientRequest
    .tokenLocation(ACCESS_TOKEN_URL)
    .setGrantType(GrantType.AUTHORIZATION_CODE)
    .setClientId(CLIENT_ID)
    .setClientSecret(CLIENT_SECRET)
    .setRedirectURI(REDIR_URL)
    .setCode(code)
    .buildBodyMessage();
  
  GitHubTokenResponse oAuthResponse = 
    oAuthClient.accessToken(request, GitHubTokenResponse.class);
  </code></pre>
  
  <p>Each time I run my code, I get an OAuthProblemException, where the message is that I have an invalid request due to a missing parameter, access_token.</p>
  
  <p>Another StackOverflow post mentions this exception from a similar OAuth2 request, which in that case was caused by having different redirect URIs across OAuth requests. But I've made sure my redirect URIs are the same by using a named constant.  Here's the link to that post:</p>
  
  <p><a href="https://stackoverflow.com/questions/10212708/oauthproblem-missing-parameter-access-token">OAuthProblem, missing parameter access_token</a></p>
  
  <p>Now, I can print out the code returned by the first request, and paste it into a curl command run from my desktop machine:</p>
  
  <p>curl -d "code=...&amp;client_id=...&amp;client_secret=...&amp;grant_type=...&amp;redirect_uri=..." <a href="http://my_website.com" rel="nofollow noreferrer">http://my_website.com</a></p>
  
  <p>and I get a nice JSON response from my site with an access_token.</p>
  
  <p>Why does the call from Java fail, where my hand-rolled command line succeeds?</p>