title: MailChimp Access Token CURL Request Not Working
body: <p>I am attempting to get a MailChimp access token but having issues. I can successfully login request "code", but when I go to request the access token I get a weird response such as this: </p>
  
  <pre><code>HTTP/1.1 400 Bad Request
  Server: nginx
  Content-Type: application/json
  Content-Length: 53
  Expires: Thu, 19 Nov 1981 08:52:00 GMT
  Cache-Control: no-store
  Pragma: no-cache
  X-UA-Compatible: IE=edge,chrome=1
  P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"
  Content-Encoding: gzip
  Vary: Accept-Encoding
  Date: Fri, 12 Feb 2016 00:58:14 GMT
  Connection: close
  Set-Cookie: _AVESTA_ENVIRONMENT=prod; path=/
  Set-Cookie: PHPSESSID=gjqtq7kelntldr82aonhpl3id3; expires=Fri, 12-Feb-2016 01:22:14 GMT; path=/; secure; HttpOnly
  Set-Cookie: _TEST_COOKIE=9957289b5c4e0a63b4d5; path=/
  Set-Cookie: PHPSESSDATA=2a45226783e34312753e142108bb48a8a0789b89%3A1455240134%3AeNoDAAAAAAE%3D; expires=Fri, 12-Feb-2016 01:22:14 GMT; path=/; domain=login.mailchimp.com; secure; httponly
  </code></pre>
  
  <p>Here is my code: </p>
  
  <pre><code>$url = 'https://login.mailchimp.com/oauth2/token';
  $client_id = 'xxxxxxxx';
  $client_secret = 'xxxxxxxxx'; 
  $redirect_uri = 'http://127.0.0.1/mailChimp/complete.php';
  $code = $_GET['code'];
  $fields = array(
          'grant_type' =&gt; 'authorization_code',
          'client_id' =&gt; $client_id,
          'client_secret' =&gt; $client_secret,
          'code' =&gt; $code,
          'redirect_URI' =&gt; $redirect_url
      );
  
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);   
  curl_setopt($ch, CURLOPT_HEADER, TRUE);     
  curl_setopt($ch, CURLOPT_TIMEOUT, TRUE);        
  curl_setopt($ch, CURLOPT_USERAGENT, 'oauth2-draft-v10');
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  // curl_setopt($ch, CURLOPT_ENCODING, "application/json");
  $value = http_build_query($fields); //params is an array
  curl_setopt($ch, CURLOPT_POSTFIELDS, $value);
  $res=curl_exec($ch);
  curl_close();
  echo '&lt;pre&gt;';
  print_r($res);
  echo '&lt;/pre&gt;';
  die; 
  </code></pre>
  
  <p>Ive gone through these docs: <a href="https://apidocs.mailchimp.com/oauth2/" rel="nofollow">https://apidocs.mailchimp.com/oauth2/</a>
  And these docs: <a href="http://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/" rel="nofollow">http://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/</a>
  And I simply cannot get an adequate response. </p>
  
  <p>Thanks for your help.</p>