PHPackages                             eugenecooper/pinterest-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. eugenecooper/pinterest-php

ActiveLibrary

eugenecooper/pinterest-php
==========================

PHP Wrapper for consuming the Pinterest API.

1.1.3(8y ago)017MITPHP

Since Sep 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/eugenecooper/pinterest-php)[ Packagist](https://packagist.org/packages/eugenecooper/pinterest-php)[ RSS](/packages/eugenecooper-pinterest-php/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (5)Versions (15)Used By (0)

Pinterest PHP
=============

[](#pinterest-php)

An easy-to-use wrapper for the [Pinterest API](https://developers.pinterest.com/tools/api-explorer/).

 [![Pinterest PHP](banner.png)](banner.png)

 [![Build Status](https://camo.githubusercontent.com/168fa7165882fc5c37b5fd79cd3e43fac31c1dfbb62fb3576deaa2998c1a8589/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f68616e736f74742f70696e7465726573742d7068702e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/hansott/pinterest-php) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/d85ca379b2d3762ec296ef63d394a922694a1c3d5db74c213285d80c17fcbf74/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f68616e736f74742f70696e7465726573742d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hansott/pinterest-php/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/2cfa64af4f94a4ba96a7f0f2652290023aaff01ea2b94e7731487b333bf3b9e0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f68616e736f74742f70696e7465726573742d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hansott/pinterest-php/?branch=master) [![Packagist](https://camo.githubusercontent.com/5ad80b364568d83e1b59569f12d267e102c034460121ffcbfbcf0bbd326f84a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616e736f74742f70696e7465726573742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hansott/pinterest-php) [![Packagist](https://camo.githubusercontent.com/2443a81f291b4ee757aef52df15730c24d7d802ae16083a9d6330bfe5650051f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616e736f74742f70696e7465726573742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hansott/pinterest-php)

Install
-------

[](#install)

Via [Composer](https://getcomposer.org/)

```
$ composer require hansott/pinterest-php
```

Usage
-----

[](#usage)

### Authentication

[](#authentication)

To use the API, you need an access token from Pinterest. [Create a new Pinterest application](https://developers.pinterest.com/apps/) if you haven't already. You then get a client ID and a client secret, specific for that application.

Back in your PHP application, create a `Pinterest\Http\ClientInterface` instance (the default is `Pinterest\Http\BuzzClient`) and use it to create an `Pinterest\Authentication` instance:

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

Replace the `$clientId` and `$clientSecret` variables with the data of [your Pinterest application](https://developers.pinterest.com/apps/).

You can now let your user authenticate with your application be redirecting them to the URL obtained by a call to `$auth->getAuthenticationUrl()`, like this:

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

- The redirect URL is the URL to the page where pinterest will send us the authentication code for the user registering with your application. This URL needs to be accessible over https, and it has to be filled into to form of your Pinterst application (in the Pinterest backend).
- The second parameter is an array of permissions your app needs on the user's account. There needs to be at least one here.
- The validation state is a random code that you generate for the user registering, and persist (in SESSION for instance). Pinterest will send it back to us for further reference.

When your application user agrees to let your app take control of their Pinterest account via the API, Pinterest will redirect them to the URL you provided as redirect URL, with some added GET parameters. The most important being "code", which we'll trade for an OAuth access token in the next step. They'll also send the validation state back to us as a GET parameter so we can check if we expected this call.

The last step in the process is trading that code for an access token:

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

You should persist that token safely at this point. You can use it from now on to connect to the Pinterest API from your application, on behalf of the user.

Initialize the `Pinterest\Api` class:

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

Using the `Pinterest\Api` instance in `$api`, you can now make authenticated API requests to Pinterest's API on behalf of the user.

### Get the authenticated user

[](#get-the-authenticated-user)

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

### Get a user

[](#get-a-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
}
```

### Get a board

[](#get-a-board)

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

### Update a board

[](#update-a-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
```

### Get the boards of the authenticated user

[](#get-the-boards-of-the-authenticated-user)

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

### Get the pins of the authenticated user

[](#get-the-pins-of-the-authenticated-user)

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

See [Get the next items of a paged list](#get-the-next-items-of-a-paged-list)

### Get the pins of a board

[](#get-the-pins-of-a-board)

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

See [Get the next items of a paged list](#get-the-next-items-of-a-paged-list)

### Get the followers of the authenticated user

[](#get-the-followers-of-the-authenticated-user)

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

See [Get the next items of a paged list](#get-the-next-items-of-a-paged-list)

### Get the boards that the authenticated user follows

[](#get-the-boards-that-the-authenticated-user-follows)

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

See [Get the next items of a paged list](#get-the-next-items-of-a-paged-list)

### Get the users that the authenticated user follows

[](#get-the-users-that-the-authenticated-user-follows)

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

See [Get the next items of a paged list](#get-the-next-items-of-a-paged-list)

### Get the interests that the authenticated user follows

[](#get-the-interests-that-the-authenticated-user-follows)

Example: [Modern architecture](https://www.pinterest.com/explore/901179409185)

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

See [Get the next items of a paged list](#get-the-next-items-of-a-paged-list)

### Follow a user

[](#follow-a-user)

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

### Create a board

[](#create-a-board)

```
$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
}
```

### Delete a board

[](#delete-a-board)

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

### Create a pin

[](#create-a-pin)

```
$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
}
```

### Delete a pin

[](#delete-a-pin)

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

### Get the next items of a paged list

[](#get-the-next-items-of-a-paged-list)

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

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Hans Ott](https://github.com/hansott)
- [Toon Daelman](https://github.com/turanct)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 71.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~48 days

Recently: every ~115 days

Total

14

Last Release

3253d ago

Major Versions

0.5.0 → 1.0.02016-03-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/75191f939aee64e753855a3601c2180ba3d8242fe06139929e1a431c67fd2cda?d=identicon)[eugenecooper](/maintainers/eugenecooper)

---

Top Contributors

[![hansott](https://avatars.githubusercontent.com/u/3886384?v=4)](https://github.com/hansott "hansott (87 commits)")[![turanct](https://avatars.githubusercontent.com/u/1728360?v=4)](https://github.com/turanct "turanct (28 commits)")[![eugenecooper](https://avatars.githubusercontent.com/u/8261869?v=4)](https://github.com/eugenecooper "eugenecooper (4 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eugenecooper-pinterest-php/health.svg)

```
[![Health](https://phpackages.com/badges/eugenecooper-pinterest-php/health.svg)](https://phpackages.com/packages/eugenecooper-pinterest-php)
```

###  Alternatives

[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[phan/phan

A static analyzer for PHP

5.6k11.2M1.1k](/packages/phan-phan)[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.5k74.6k86](/packages/pocketmine-pocketmine-mp)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4723.6M20](/packages/coenjacobs-mozart)[felixfbecker/advanced-json-rpc

A more advanced JSONRPC implementation

25578.7M6](/packages/felixfbecker-advanced-json-rpc)[keepa/php_api

API Framework for Keepa.com

55474.9k](/packages/keepa-php-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
