I'm trying to use the Pinterest API using PHP, but so far it doesn't really work. I use this guide to get started:
https://developers.pinterest.com/docs/api/authentication/
I got everything working now except for step 3. The documentation says it's just a simple request to
https://api.pinterest.com/v1/me/?access_token=<YOUR-ACCESS-TOKEN>
- Making authenticated requests
Finally, once you have an access token, you can make authorized requests on the users behalf using OAuth 2.0 Bearer tokens supplied via the Authorization request header or via a request parameter named access_token (supplied as either a form-encoded body parameter or a URI query parameter). The Authorization header is preferred.
For example, you can visit this site on your browser:
https://api.pinterest.com/v1/me/?access_token= A sample response might look like:
{ "data": { "url": "https://www.pinterest.com/ben/", "first_name": "Ben", "last_name": "Silbermann", "id": "4788400174839062" } }
I have an access_token which looks like this:
AcFFayZKwqXuKVkj1J-0QN1fCob1FAgjuP9-OtFCg_j49UAgogXXXXX
But everytime I get this message:
{"status": "failure", "code": 3, "host": "coreapp-devplatform-devapi-181", "generated_at": "Mon, 28 Sep 2015 12:28:38 +0000", "message": "Authorization failed.", "data": null}
I use this PHP code to get data from the URL:
$curl = curl_init($url);
curl_setopt_array($curl, array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_FORBID_REUSE => true,
CURLOPT_FRESH_CONNECT => true,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => array("Content-Type: application/x-www-form-urlencoded"),
CURLOPT_NOBODY => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30,
CURLOPT_USERAGENT => self::userAgent()
));
$result = curl_exec($curl);
var_dump($result);
$errorCode = curl_errno($curl);
$respCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
I just gone through this same error, but for different endpoint. Try this code
$ch = curl_init();
$url = "https://api.pinterest.com/v1/me/?access_token='YOUR_ACCESS_TOKEN'";
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);
print_r($result);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With