PHP code example of siapepfrance / pinterest-php-client

1. Go to this page and download the library: Download siapepfrance/pinterest-php-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

siapepfrance / pinterest-php-client example snippets


use SiapepFrance\Pinterest\Pinterest;

$pinterest = new Pinterest(CLIENT_ID, CLIENT_SECRET);

$loginurl = $pinterest->auth->getLoginUrl(REDIRECT_URI, array('read_public'));
echo '<a href=' . $loginurl . '>Authorize Pinterest</a>';

if(isset($_GET["code"])){
    $token = $pinterest->auth->setRedirectUri(REDIRECT_URI)->getOAuthToken($_GET["code"]);
    $pinterest->auth->setOAuthToken($token->access_token);
}

$userAccount = $pinterest->user_accounts->get();
echo $userAccount;

$pinterest->user_accounts->get();

$pins = $pinterest->boards->listBoards();
$pins->all();

$pins = $pinterest->boards->listBoards();
$pins->get(0);

$pins = $pinterest->boards->listBoards();
$pins->hasNextPage();

$pins = $pinterest->boards->getNextPage();
$pins->getNextPage();

$pins = $pinterest->boards->listBoards();
$pins->pagination['cursor'];

$pinterest->auth->getLoginUrl("https://pinterest.dev/callback.php", array("boards:read,boards:write,boards:write_secret,pins:read,pins:write,pins:write_secret"));

$pinterest->auth->setRedirectUri($redirect_uri);

$pinterest->auth->getOAuthToken($code);

$pinterest->auth->setOAuthToken($access_token);

$pinterest->auth->refreshOAuthToken($access_token);

$pinterest->auth->getState();

$pinterest->auth->setState($state);

$pinterest->getRateLimit();

$pinterest->getRateLimitRemaining();

$pinterest->user_accounts->get();

$pinterest->user_accounts->getAnalytics($data);

$pinterest->boards->listBoards();

$pinterest->boards->get();

$pinterest->boards->create(array(
    "name"          => "Test board from API",
    "description"   => "Test Board From API Test",
    "privacy"       => "PUBLIC"
));

$pinterest->boards->edit("1234567890", array(
    "name"  => "Test board after edit"
));

$pinterest->boards->pins("1234567890", []);

$pinterest->boards->delete("1234567890", []);

$pinterest->sections->create("1234567890", array(
    "name" => "Test from API"
));

$pinterest->sections->update("1234567890", "10111213", array(
    "name" => "Test from API"
));

$pinterest->sections->get("1234567890");

$pinterest->sections->pins("1234567890", "10111213");

$pinterest->sections->delete("1234567890", "10111213");

$pinterest->pins->get("10111213");

$pinterest->pins->fromBoard("1234567890");

$pinterest->pins->create(array(
    'link' => 'https://www.siapep.fr',
    'title' => 'Test board from API',
    'description' => $message,
    'alt_text' => "",
    'board_id' => '1234567890',
    'board_section_id' => null,
    'media_source' => [
        'source_type' => 'image_url',
        'url' => 'https://www.siapep.fr/api/public/file/23/getcontent'
    ]
));


// Get the image and convert into string
$img = file_get_contents('/path/to/image.png');

// Encode the image string data into base64
$imgBase64 = base64_encode($img);

$pinterest->pins->create(array(
    'link' => 'https://www.siapep.fr',
    'title' => 'Test Pin from API',
    'description' => 'Test Pin description from API',
    'alt_text' => "",
    'board_id' => '1234567890',
    'board_section_id' => null,
    'media_source' => [
        'source_type' => 'image_base64',
        'content_type' => 'image/png',
        'data' => $imgBase64
    ]
));

$pinterest->pins->edit("15161718", array(
    'description' => 'Test Pin description from API bis',
));

$pinterest->pins->delete("181692166190246650");

$pinterest->ad_accounts->get();

$pinterest->ad_accounts->getAnalytics($adAccountId, $data);

$pinterest->ad_accounts->getCampaigns($adAccountId, $data);

$pinterest->ad_accounts->getCampaignAnalytics($adAccountId, $data);

$pinterest->ad_accounts->getAdGroups($adAccountId, $data);

$pinterest->ad_accounts->getAdGroupAnalytics($adAccountId, $data);

$pinterest->ad_accounts->getAds($adAccountId, $data);

$pinterest->ad_accounts->getAdAnalytics($adAccountId, $data);

composer