title: Instagram Basic Display API - This authorization code has been used
body: <p>I need to allow users of my platform to link their Instagram account through the Instagram Basic Display API.
  When I make the call to get the code to exchange for the Access Token, it is always the same and results in an error in the next step.</p>
  <p>These are the steps I'm performing, following <a href="https://developers.facebook.com/docs/instagram-basic-display-api/getting-started" rel="nofollow noreferrer">this official guide</a>:</p>
  <ol>
  <li>GET request with these parameters: <code>https://api.instagram.com/oauth/authorize?client_id=XXXXX&amp;redirect_uri=XXXXX&amp;scope=user_profile&amp;response_type=code</code></li>
  <li>POST request to <code>https://api.instagram.com/oauth/access_token</code> via cURL in PHP passing the parameters as the second code snippet below</li>
  <li>GET request with <code>'https://graph.instagram.com/' . $result-&gt;user_id . '?fields=username&amp;access_token=' . $result-&gt;access_token</code> via cURL in PHP</li>
  </ol>
  <p>The process fail between 1 and 2, because step one always returns the same code even though <strong>I have made several attempts with different accounts</strong></p>
  <p>This is the HTML form for the code request. Successfully opens the Instagram login page:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;a class=&quot;insta-con&quot; href=&quot;https://api.instagram.com/oauth/authorize?client_id=XXXXX&amp;redirect_uri=XXXXX&amp;scope=user_profile&amp;response_type=code&quot;&gt;
     &lt;img src=&quot;assets/images/instalogo.png&quot; alt=&quot;Connetti a Instagram&quot;&gt;
     &lt;p&gt;Connect to Instagram&lt;/p&gt;
  &lt;/a&gt;
  </code></pre>
  <p>The login form return always the same code, also with different accounts, resulting in error <code>{&quot;error_type&quot;: &quot;OAuthException&quot;, &quot;code&quot;: 400, &quot;error_message&quot;: &quot;This authorization code has been used&quot;}</code> in this next request:</p>
  <pre class="lang-php prettyprint-override"><code>$fields = array(
      'client_id'     =&gt; 'XXXXXX',
      'client_secret' =&gt; 'XXXXXXXXX',
      'grant_type'    =&gt; 'authorization_code',
      'redirect_uri'  =&gt; 'https://www.XXXXXXX.it/connect.php',
      'code'          =&gt; $_GET['code']
  );
  $url = 'https://api.instagram.com/oauth/access_token';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  curl_setopt($ch, CURLOPT_POST,true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  curl_setopt($ch, CURLOPT_VERBOSE,true);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
  $result = curl_exec($ch);
  if(curl_errno($ch)) {
      echo 'Curl error: ' . curl_error($ch);
  }
  curl_close($ch);
  $result = json_decode($result, true);
  </code></pre>
  <p>So my question is: Why am I getting always the same code despite different accounts?</p>