title: Generate Pinterest access token dynamically with PHP API
body: <p>I developed a Pinterest plugin for WordPress users. Now, I am facing token generation problem with Pinterest API. I have set and configure accordingly to <a href="https://developers.pinterest.com/docs/api/overview/" rel="nofollow noreferrer">API docs</a>. In <strong>Step 1</strong> you get an access code and in <strong>Step 2</strong>, you need to request for access token with the help of access code. Step 1 going to succeed but in Step 2 throwing error response.</p>
  <p>I already asked to Pinterest Support through email but they are saying:</p>
  <blockquote>
  <p>We're a small team right now and we can't offer development support or
  consult for the API just yet. For more support around using our API,
  we encourage you to use developer resources like <strong>Stack Overflow</strong>.</p>
  </blockquote>
  <p><strong>The code I did:</strong>
  I already made an <a href="https://developers.pinterest.com/apps/" rel="nofollow noreferrer">APP</a> and used the give App ID and Secret, and redirect URL also set in APP same below:</p>
  <pre><code>$client_id = &quot;&amp;client_id=496200555XXXXXXXX1778834&quot;;
  $client_secret = &quot;&amp;client_secret=48d62d7c21aa432bb5320c0aeXXXXXXXXXXX75933f6295db1bae61ffa66ca31&quot;;
  $authorization_url = &quot;https://api.pinterest.com/oauth/?&quot;;
  $response_type = &quot;response_type=code&quot;;
  $state = &quot;&amp;state=weblizar_app&quot;;
  $scope = &quot;&amp;scope=read_public,read_relationships&quot;;
  $redirect_uri = &quot;&amp;redirect_uri=https://weblizar.com/pinterest-access-token.php&quot;;
  $access_token_url = &quot;https://api.pinterest.com/v1/oauth/token?&quot;;
  $grant_type = &quot;grant_type=authorization_code&quot;;
  
  // Step 1: get authorization code
  $access_code_url = $authorization_url . $response_type . $redirect_uri . $client_id . $scope . $state;
  echo &quot;&lt;a href=$access_code_url&gt;Get Authorization Code&lt;/a&gt;&quot;;
  
  // Step 2: exchange the access token
  if(isset($_GET['code'])) {
      $authorization_code = $_GET['code'];
      $access_code_url = $access_token_url . $grant_type . $client_id . $client_secret .&quot;&amp;code=&quot; .$authorization_code; echo &quot;&lt;br&gt;&quot;;
      
      echo &quot;Curl post URL - &quot;; echo &quot;&lt;br&gt;&quot;;
      $ch = curl_init();
      echo $url = $access_code_url;
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10);
      $result = trim(curl_exec($ch));
      curl_close($ch);
      
      echo &quot;Curl Post Response&quot;; echo &quot;&lt;br&gt;&quot;;
      echo &quot;&lt;pre&gt;&quot;;   
      print_r($result);  
      echo &quot;&lt;pre&gt;&quot;;
  }
  </code></pre>
  <p><strong>Response Returned After Step 2</strong></p>
  <pre><code>{
    &quot;message&quot;: &quot;405: Method Not Allowed&quot;,
    &quot;type&quot;: &quot;http&quot;
  }
  </code></pre>
  <p>As everyone knows <a href="https://developers.pinterest.com/tools/access_token/" rel="nofollow noreferrer">Pinterest token generation URL</a> no more available for users or closed down.</p>
  <p>You can test, the code is live on site: <a href="https://weblizar.com/pinterest-access-token.php" rel="nofollow noreferrer">https://weblizar.com/pinterest-access-token.php</a></p>
  <p>Any kind of help really appreciated. Thanks in advance.</p>