This PHP library will help you to work with your Pinterest account. You don't need to register application in Pintererst to get access token for api. Use only your account login and password.
Some functions use pinterest navigation through results, for example, get user followers. Function returns generator object with api results as batches in every iteration. By default functions return all pinterest result batches, but you can pass batches num as second argument. For example,
$bot->pins->search('query', 2)
will return only 2 batches of search results.
Library requires CURL extension and PHP 5.6 or above.
Via composer:
composer require "seregazhuk/pinterest-bot:*"
// You may need to amend this path to locate composer's autoloader
require('vendor/autoload.php');
use seregazhuk\PinterestBot\Factories\PinterestBot;
$bot = PinterestBot::create();
// login
$bot->login('mypinterestlogin', 'mypinterestpassword');
// get lists of your boards
$boards = $bot->boards->forUser('yourUserName');
$bot->pins->create('http://exmaple.com/image.jpg', $boards[0]['id'], 'pin description');
Or you may skip login, if you want. It is only required for such operations as likes, follows and making pins.
Get all user's boards
$boards = $bot->boards->forUser($username);
Get full board info by boardName and userName. Here you can get board id, for further functions (for examaple, pin creating or following boards).
$info = $bot->boards->info($username, $board);
Create a new board. As third parameter you can pass privacy. It is public by default, or secret if private.
// create a public board
$bot->boards->create('name', 'description');
// create a private board
$bot->boards->create('name', 'description', 'secret');
Delete board by id
$bot->boards->delete($boardId);
Follow/unfollow board by ID
$bot->boards->follow($boardId);
$bot->boards->unfollow($boardId);
Get all pins for board by ID
foreach($bot->boards->pins($boardId) as $pinsBatch)
{
// ...
}
Get board followers. Uses pinterest api pagination.
foreach($bot->boards->followers($boardId) as $followersBatch)
{
// ...
}
Notice! Try not to be very aggressive when pinning or commetning pins, or pinterest will gonna ban you.
Get pin info by its id.
$info = $bot->pins->info(1234567890);
Create new pin. Accepts image url, board id, where to post image, description and preview url.
$pinId = $bot->pins->create('http://exmaple.com/image.jpg', $boards[0]['id'], 'pin description');
You can specify a link for pin (source) as fourth argument. If not set, link is equal to image url.
$pinId = $bot->pins->create('http://exmaple.com/image.jpg', $boards[0]['id'], 'pin description', 'http://site.com');
Repin other pin by its id.
$bot->pins->repin($pinId, $boards[0]['id'], 'my repin');
Delete pin by id.
$bot->pins->delete($pinId);
Like/dislike pin by id.
$bot->pins->like($pinId);
$bot->pins->unLike($pinId);
Write a comment.
$result = $bot->pins->comment($pinId, 'your comment');
// Result contains info about written comment. For example,
// comment_id if you want to delete it.
Delete a comment.
$bot->pins->deleteComment($pinId, $commentId);
Follow/unfollow user by ID
$bot->pinners->follow($userId);
$bot->pinners->unfollow($userId);
Get user info by username
$userData = $bot->pinners->info($username);
Get user following. Uses pinterest api pagination.
foreach($bot->pinners->following('username') as $followingBatch)
{
// ...
}
Get user followers. Uses pinterest api pagination.
foreach($bot->pinners->followers('username') as $followersBatch)
{
// ...
}
Follow/unfollow interest by ID
$bot->interests->follow($interestId);
$bot->interests->unfollow($interestId);
##Conversations
Write a message to user by id. You may specify one user by id, or pass an array of user ids.
$bot->conversations->sendMessage($userId, 'message text');
Add pin by id to message
$pinId = 123456789;
$bot->conversations->sendMessage($userId, 'message text', $pinId);
Email param may be string or array of emails.
$bot->conversations->sendEmail('[email protected]', 'message text');
Attach pin to email
$bot->conversations->sendEmail('[email protected]', 'message text', $pindId);
Get array of last conversations
$conversations = $bot->conversations->last();
Search functions use pinterest pagination in fetching results and return generator.
foreach($bot->pins->search('query') as $pinsBatch)
{
// ...
}
foreach($bot->pinners->search('query') as $pinnersBatch)
{
// ...
}
foreach($bot->boards->search('query') as $boardsBatch);
{
// ...
}
Change profile. Available settings are: last_name, first_name, username, about, location and website_url:
$bot->user->profile(['first_name'=>'My_name']);
Get latest user's news:
$news = $bot->news->latest();
You can check for occurred errors after requests with method getLastError():
$error = $bot->getLastError();
print_r($error);
You can set UserAgent string for bot like this:
$userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0';
$bot = PinterestBot::create($userAgent);