I have developed a Pinterest plugin for WordPress users. Now, facing token generation problem with Pinterest API. I have set and configure accordingly to API docs. In Step 1 you get an access code and in Step 2, 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.
I already asked to Pinterest Support through email but they are saying:
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 Stack Overflow.
The code I did: I already made an APP and used the give App ID and Secret, and redirect URL also set in APP same below:
$client_id = "&client_id=496200555XXXXXXXX1778834";
$client_secret = "&client_secret=48d62d7c21aa432bb5320c0aeXXXXXXXXXXX75933f6295db1bae61ffa66ca31";
$authorization_url = "https://api.pinterest.com/oauth/?";
$response_type = "response_type=code";
$state = "&state=weblizar_app";
$scope = "&scope=read_public,read_relationships";
$redirect_uri = "&redirect_uri=https://weblizar.com/pinterest-access-token.php";
$access_token_url = "https://api.pinterest.com/v1/oauth/token?";
$grant_type = "grant_type=authorization_code";
// Step 1: get authorization code
$access_code_url = $authorization_url . $response_type . $redirect_uri . $client_id . $scope . $state;
echo "<a href=$access_code_url>Get Authorization Code</a>";
// 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 ."&code=" .$authorization_code; echo "<br>";
echo "Curl post URL - "; echo "<br>";
$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 "Curl Post Response"; echo "<br>";
echo "<pre>";
print_r($result);
echo "<pre>";
}
Response Returned After Step 2
{
"message": "405: Method Not Allowed",
"type": "http"
}
As everyone knows Pinterest token generation URL no more available for users or closed down.
You can test, the code is live on site: https://weblizar.com/pinterest-access-token.php
Any kind of help really appreciated. Thanks in advance.