title: OAuth2 returns invalid_client error
body: <p>good day,</p>
  
  <p>I'm having trouble with getting the access token. I've followed the guide here: <a href="http://developers.box.com/oauth/" rel="nofollow">http://developers.box.com/oauth/</a>
  and already get my <strong>client_id</strong>, <strong>client_secret</strong>, and set the <strong>redirect_uri</strong> on the App settings (<em>OAuth2 parameters</em>) section.</p>
  
  <p>Here is the code for the file <strong>client.php</strong></p>
  
  <pre><code>&lt;?php
      $client_id = 'my_client_id_here'; //removed
      $post_url = 'https://www.box.com/api/oauth2/authorize';
  
      include 'includes/header.php';
  ?&gt;
      &lt;div id="content"&gt;
          &lt;form action="&lt;?php echo $post_url; ?&gt;" type="POST" enctype="application/x-www-form-urlencoded"&gt;
              &lt;input type="text" name="response_type" value="code"&gt;
              &lt;input type="text" name="client_id" value="&lt;?php echo $client_id; ?&gt;"&gt;
              &lt;input type="text" name="state" value="vexhax97td8xf_SomeTemporaryValueForTesting"&gt;
              &lt;input type="submit"&gt;
          &lt;/form&gt;
          &lt;div id="response"&gt;&lt;/div&gt;
      &lt;/div&gt;
  
  &lt;?php
      include 'includes/footer.php';
  ?&gt;
  </code></pre>
  
  <p>and here's code for the file <strong>something.php</strong> (this is where the <strong>redirect_uri</strong> will go)</p>
  
  <pre><code>&lt;?php
  
  $client_id =  'my_client_id_here'; //removed
  $client_secret =  'my_client_secrect_here'; //removed
  $post_url = 'https://www.box.com/api/oauth2/token';
  
  $code = $_GET['code'];
  
  include 'includes/header.php';
  
  $fields_params = array(
          "grant_type" =&gt; 'authorization_code',
          "code" =&gt; $code,
          "client_id" =&gt; $client_id,
          "client_secret" =&gt; $client_secret
      );
  
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_URL, $post_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_params);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Content-Type: application/json',
      'Accept: application/json'
  ));
  
  $data = curl_exec($ch); 
  curl_close($ch);
  
  $json = json_decode($data, true);
  var_dump($json);
  
  ?&gt;
      &lt;div id="content"&gt;
          &lt;?php 
              //Nothing fancy, just for displaying passed values
              if (isset($_GET))
                  var_dump($_GET); 
  
              if (isset($_POST))
                  var_dump($_POST); 
          ?&gt;
      &lt;/div&gt;
  
  &lt;?php
      include 'includes/footer.php';
  ?&gt;
  </code></pre>
  
  <p>...now what happens is,</p>
  
  <p>1.) on the first step (<strong>client.php</strong>), there is a form there with submit button.</p>
  
  <p>2.) After i clicked on the submit button, i get redirected to the Box' login page with the button "Authorize".</p>
  
  <p>3.) after entering login details and allow granting access for my app. I now gets redirected to the <strong>redirect_uri</strong> that i've set on the App settings (<strong>something.php</strong>), where in this file, it will execute curl post to get an access token, but i get stuck at this part, the curl result returns with the error:</p>
  
  <pre><code>array(2) { ["error"]=&gt; string(14) "invalid_client" ["error_description"]=&gt; string(34) "The client credentials are invalid" }
  </code></pre>
  
  <p>I'm sure that I have entered my <strong>client_id</strong> and <strong>client_secret</strong> correctly which I've obtained from the App settings. And the url for the <strong>redirect_uri</strong>, is also SSL enabled. </p>
  
  <p>Any solutions, ideas why this is happening?</p>
  
  <p>Thank you for your help.</p>