Skip to content

rub3nlh/php-pinterest-bot

 
 

Repository files navigation

Pinterest Bot for PHP

Build Status Circle CI Code Climate Scrutinizer Code Quality Test Coverage Total Downloads

This PHP class 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.

Dependencies

API requires CURL extension and PHP 5.5 or above.

Installation

Via composer:

php composer.phar require "seregazhuk/pinterest-bot:*"

Quick Start

use seregazhuk\PinterestBot\PinterestBot;

$bot = new PinterestBot('mypinterestlogin', 'mypinterestpassword');
$bot->login();

Boards

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);

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)
{
    // ...
}

Pins

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->createApiResponse('http://exmaple.com/image.jpg', $boards[0]['id'], 'pin description');

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);

Pinners

Get your account name

$bot->pinners->myAccountName(); 

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)
{
	// ...
}

Interests

Follow/unfollow interest by ID

$bot->interests->follow($interestId);
$bot->interests->unfollow($interestId);

##Conversations Write a message to user

$bot->conversations->sendMessage($userId, 'message text');

Get array of last conversations

$conversations = $bot->conversations->last();

Search

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);
{
	// ...
}

Errors handling

You can check for occurred errors after requests with method getLastError():

$error = $bot->getLastError();
print_r($error);

About

PHP Pinterest Bot

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%