title: google oauth2 grant_type=authorization_code returns Error processing OAuth 2 request
body: <p>the piece of the code as</p>
  
  <p>the post url as <a href="https://accounts.google.com/o/oauth2/token" rel="nofollow">https://accounts.google.com/o/oauth2/token</a></p>
  
  <p>the scope is 'https://www.googleapis.com/auth/userinfo.profile <a href="https://www.googleapis.com/auth/userinfo.email" rel="nofollow">https://www.googleapis.com/auth/userinfo.email</a> https://www.google.com/m8/feeds/'</p>
  
  <p>grant_type as authorization_code</p>
  
  <p>code is from the google</p>
  
  <pre>
          my %args = (
              client_id     => $config->{client_id},
              client_secret => $config->{client_secret},
              redirect_uri  => $config->{redirect_uri},
              scope         => $config->{scope},
              grant_type    => $config->{grant_type},
              code          => $code,
          );
          my $ua = LWP::UserAgent->new;
          my $ua_response = $ua->post( $uri, \%args );
  </pre>
  
  <p>and what I get is something like below: (the response is html escaped)</p>
  
  <pre>$VAR1 = \bless( {
  
  '_content' => '&lt;HTML> &lt;HEAD> &lt;TITLE>Error processing OAuth 2 request&lt;/TITLE> &lt;/HEAD> &lt;BODY BGCOLOR="#FFFFFF" TEXT="#000000"> &lt;H1>Error processing OAuth 2 request&lt;/H1> &lt;H2>Error 500&lt;/H2> &lt;/BODY> &lt;/HTML> ',
  '_headers' => bless( { 'cache-control' => 'no-cache, no-store, max-age=0, must-revalidate', 'client-date' => 'Wed, 16 May 2012 09:21:26 GMT', 'client-peer' => '173.194.74.84:443', 'client-response-num' => 1, 'client-ssl-cert-issuer' => '/C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA', 'client-ssl-cert-subject' => '/C=US/ST=California/L=Mountain View/O=Google Inc/CN=accounts.google.com', 'client-ssl-cipher' => 'RC4-SHA', 'client-ssl-warning' => 'Peer certificate not verified', 'connection' => 'close', 'content-type' => 'text/html; charset=UTF-8', 'date' => 'Wed, 16 May 2012 09:21:21 GMT', 'expires' => 'Fri, 01 Jan 1990 00:00:00 GMT', 'pragma' => 'no-cache', 'server' => 'GSE', 'title' => 'Error processing OAuth 2 request', 'x-content-type-options' => 'nosniff', 'x-frame-options' => 'SAMEORIGIN', 'x-xss-protection' => '1; mode=block' }, 'HTTP::Headers' ),
  
  '_msg' => 'Error processing OAuth 2 request',
  
  '_protocol' => 'HTTP/1.1',
  
  '_rc' => '500',
  
  '_request' => bless( { '_content' => 'grant_type=authorization_code&redirect_uri=http%3A%2F%2Fwww.xxx.com%2Foauth%2Fcallback%2Fgoogle&client_secret=xxx&client_id=xxx.apps.googleusercontent.com&code=4%2FSihUM4Zw1OPiWLMi-gdGvKOfiY4M.cggfQHKT31QagrKXntQAax3e4-qpbgI&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.google.com%2Fm8%2Ffeeds%2F', 
  '_headers' => bless( { 'content-length' => 424, 'content-type' => 'application/x-www-form-urlencoded', 'user-agent' => 'libwww-perl/6.04' }, 'HTTP::Headers' ),
   '_method' => 'POST', 
  '_uri' => bless( do{\(my $o = 'https://accounts.google.com/o/oauth2/token')}, 'URI::https' ), 
  '_uri_canonical' => ${$VAR1}->{'_request'}->{'_uri'} }, 
  
  'HTTP::Request' ) }, 'HTTP::Response' );</pre>
  
  <p>and actually it works sometimes but not for all the cases.</p>
  
  <p>is there anything wrong?</p>