Я использую pinterest api для создания пинов Ошибка авторизации
Ошибка авторизации
Я пытаюсь получить платформу, на которой пользователи могут публиковать записи на всех платформах, которые они хотят. Я использую pinterest, ноиз-за этой ошибки я извиняюсь за плохой английский
PinterestClasss.php
<?php
namespace App;
use DirkGroenen\Pinterest\Pinterest;
class PinterestClass {
private $pinterest;
public function __construct()
{
$this->pinterest = new Pinterest(5059747492164316462,'ac824768820a819c516de259627782449f6a94a9177025b517d70b9f81c81758');
}
public function getLoginUrl()
{
$loginurl = $this->pinterest->auth->getLoginUrl("https://localhost/social_platform/pinterest_callback.php", array('read_public'));
return $loginurl;
}
public function setAccessToken()
{
$token = $this->pinterest->auth->getOAuthToken($_GET["code"]);
$accessToken = $this->pinterest->auth->setOAuthToken($token->access_token);
}
public function getUserProfile()
{
$userProfile = $this->pinterest->users->me();
return $userProfile;
}
public function setImage()
{
$image = $this->pinterest->pins->create(array(
"note" => "Test board from API",
"image_url" => "https://cdn.vox-cdn.com/thumbor/Pkmq1nm3skO0-j693JTMd7RL0Zk=/0x0:2012x1341/1200x800/filters:focal(0x0:2012x1341)/cdn.vox-cdn.com/uploads/chorus_image/image/47070706/google2.0.0.jpg",
"board" => "Test"
));
}
}
?>
pinterest_callback.php
<?php
require_once 'bootstrap/bootstrap.php';
use App\PinterestClass;
if (isset($_GET["code"])) {
$pinterest = new PinterestClass();
$accessToken = $pinterest->setAccessToken();
$image = $pinterest->setImage();
// var_dump($image);
// $userProfile = $pinterest->getUserProfile();
}
?>
Ошибка:
Fatal error: Uncaught DirkGroenen\Pinterest\Exceptions\PinterestException: Pinterest error (code: 401) with message: Authorization failed. in E:\xampp\htdocs\Social_Platform\vendor\dirkgroenen\pinterest-api-php\src\Pinterest\Transport\Request.php:246 Stack trace: #0 E:\xampp\htdocs\Social_Platform\vendor\dirkgroenen\pinterest-api-php\src\Pinterest\Transport\Request.php(98): DirkGroenen\Pinterest\Transport\Request->execute('POST', 'https://api.pin...', Array) #1 E:\xampp\htdocs\Social_Platform\vendor\dirkgroenen\pinterest-api-php\src\Pinterest\Endpoints\Pins.php(66): DirkGroenen\Pinterest\Transport\Request->post('pins', Array) #2 E:\xampp\htdocs\Social_Platform\app\PinterestClass.php(40): DirkGroenen\Pinterest\Endpoints\Pins->create(Array) #3 E:\xampp\htdocs\Social_Platform\pinterest_callback.php(8): App\PinterestClass->setImage() #4 {main} thrown in E:\xampp\htdocs\Social_Platform\vendor\dirkgroenen\pinterest-api-php\src\Pinterest\Transport\Request.php on line 246