PHP code example of eugenecooper / pinterest-php

1. Go to this page and download the library: Download eugenecooper/pinterest-php 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/ */

    

eugenecooper / pinterest-php example snippets


$client = new Pinterest\Http\BuzzClient();
$auth = new Pinterest\Authentication($client, $clientId, $clientSecret);

use Pinterest\App\Scope;

$url = $auth->getAuthenticationUrl(
    'https://your/redirect/url/here',
    array(
        Scope::READ_PUBLIC,
        Scope::WRITE_PUBLIC,
        Scope::READ_RELATIONSHIPS,
        Scope::WRITE_RELATIONSHIPS,
    ),
    'random-string'
);

header('Location: ' . $url);
exit;

$code = $_GET['code'];
$token = $auth->requestAccessToken($code);

$auth = Pinterest\Authentication::onlyAccessToken($client, $token);
$api = new Pinterest\Api($auth);

$response = $api->getCurrentUser();
if ($response->ok()) {
    $user = $response->result(); // $user instanceof Objects\User
}

// Get user by username
$response = $api->getUser('otthans');

// Get user by user id
$response = $api->getUser('314196648911734959');

if ($response->ok()) {
    $user = $response->result(); // $user instanceof Objects\User
}

$response = $api->getBoard('314196580192594085');
if ($response->ok()) {
    $board = $response->result(); // $board instanceof Objects\Board
}

$response = $api->getBoard('314196580192594085');
if (!$response->ok()) {
    die($response->getError());
}

$board = $response->result(); // $board instanceof Objects\Board
$board->name = 'New board name';
$board->description = 'New board description';
$response = $api->updateBoard($board);
if (!$response->ok()) {
    die($response->getError());
}

$updatedBoard = $response->result(); // $updatedBoard instanceof Objects\Board

$response = $api->getUserBoards();
if ($response->ok()) {
    $pagedList = $response->result(); // $pagedList instanceof Objects\PagedList
    $boards = $pagedList->items(); // array of Objects\Board objects
}

$response = $api->getUserLikes();
if ($response->ok()) {
    $pagedList = $response->result(); // $pagedList instanceof Objects\PagedList
    $pins = $pagedList->items(); // array of Objects\Pin objects
}

$response = $api->getBoardPins($boardId);
if ($response->ok()) {
    $pagedList = $response->result(); // $pagedList instanceof Objects\PagedList
    $pins = $pagedList->items(); // array of Objects\Pin objects
}

$response = $api->getUserFollowers();
if ($response->ok()) {
    $pagedList = $response->result(); // $boards instanceof Objects\PagedList
    $users = $pagedList->items(); // array of Objects\User objects
}

$response = $api->getUserFollowingBoards();
if ($response->ok()) {
    $pagedList = $response->result(); // $boards instanceof Objects\PagedList
    $boards = $pagedList->items(); // array of Objects\Board objects
}

$response = $api->getUserFollowing();
if ($response->ok()) {
    $pagedList = $response->result(); // $boards instanceof Objects\PagedList
    $users = $pagedList->items(); // array of Objects\User objects
}

$response = $api->getUserInterests();
if ($response->ok()) {
    $pagedList = $response->result(); // $boards instanceof Objects\PagedList
    $boards = $pagedList->items(); // array of Objects\Board objects
}

$response = $api->followUser('otthans');
if ($response->ok()) {
    // Succeeded
}

$name = 'My new board';
$optionalDescription = 'The description of the board';
$response = $api->createBoard($name, $optionalDescription);
if ($response->ok()) {
    $board = $response->result(); // $board instanceof Objects\Board
}

$boardId = '314196580192594085';
$response = $api->createBoard($boardId);
if ($response->ok()) {
    // Succeeded
}

$boardId = '314196580192594085';
$note = 'This is an amazing pin!';
$optionalLink = 'http://hansott.github.io/';

// Load an image from a url.
$image = Pinterest\Image::url('http://lorempixel.com/g/400/200/cats/');

// Load an image from a file.
$pathToFile = 'myfolder/myimage.png';
$image = Pinterest\Image::file($pathToFile);

// Load a base64 encoded image.
$pathToFile = 'myfolder/myimage.png';
$data = file_get_contents($pathToFile);
$base64 = base64_encode($data);
$image = Pinterest\Image::base64($base64);
 
$response = $api->createPin($boardId, $note, $image, $optionalLink);
if ($response->ok()) {
    $pin = $response->result(); // $pin instanceof Objects\Pin
}

$pinId = 'the-pin-id';
$response = $api->deletePin($pinId);
if ($response->ok()) {
    // Succeeded
}

$hasMoreItems = $pagedList->hasNext();
if (!$hasMoreItems) {
    return;
}
$response = $api->getNextItems($pagedList);
if (!$response->ok()) {
    die($response->getError());
}
$nextPagedList = $response->result();
bash
$ composer