PHPackages                             hansott/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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. hansott/pinterest-php

Abandoned → [dirkgroenen/pinterest-api-php](/?search=dirkgroenen%2Fpinterest-api-php)ArchivedLibrary[Authentication &amp; Authorization](/categories/authentication)

hansott/pinterest-php
=====================

PHP client for the official Pinterest API

3.2.7(6y ago)54147.9k↓15.1%20[1 issues](https://github.com/hansott/pinterest-php/issues)MITPHP

Since Sep 27Pushed 5y ago10 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (26)Used By (0)

[![Pinterest PHP](art/pinterest-php.jpg)](art/pinterest-php.jpg)
================================================================

[](#)

 [![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
```

Donate
------

[](#donate)

If you like this package, please consider buying me a coffee. Thank you for your support! 🙇‍♂️

[![Buy Me A Coffee](https://camo.githubusercontent.com/9f44ce2dc3b3eecdd02598900866ffc518801df1932849703dae1e5ce5031070/68747470733a2f2f7777772e6275796d6561636f666665652e636f6d2f6173736574732f696d672f637573746f6d5f696d616765732f6f72616e67655f696d672e706e67)](https://www.buymeacoffee.com/hansott)

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()) {
    die($response->getError());
}

$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()) {
    die($response->getError());
}

$user = $response->result(); // $user instanceof Objects\User
```

### Get a board

[](#get-a-board)

```
$response = $api->getBoard('314196580192594085');

if (!$response->ok()) {
    die($response->getError());
}

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

### Update a board

[](#update-a-board)

```
// First, get the board using getBoard()
$response = $api->getBoard('314196580192594085');

if (!$response->ok()) {
    die($response->getError());
}

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

// Or create a new board without getBoard()

$board = new Board;
$board->id = 'the-board-id';

// Then, update the fields you want to change

$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()) {
    die($response->getError());
}

$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->getUserPins();

if (!$response->ok()) {
    die($response->getError());
}

$pagedList = $response->result(); // $pagedList instanceof Objects\PagedList
$pins = $pagedList->items(); // array of Objects\Pin objects
```

### Get the pins of a board

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

```
$response = $api->getBoardPins($boardId);

if (!$response->ok()) {
    die($response->getError());
}

$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()) {
    die($response->getError());
}

$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()) {
    die($response->getError());
}

$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()) {
    die($response->getError());
}

$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()) {
    die($response->getError());
}

$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()) {
    die($response->getError());
}
```

### Unfollow a user

[](#unfollow-a-user)

```
$response = $api->unfollowUser('otthans'); // username or user ID

if (!$response->ok()) {
    die($response->getError());
}
```

### Follow a board

[](#follow-a-board)

```
$response = $api->followBoard('teslamotors', 'model-x');

if (!$response->ok()) {
    die($response->getError());
}
```

### Unfollow a board

[](#unfollow-a-board)

```
$response = $api->unfollowBoard('teslamotors', 'model-x');

if (!$response->ok()) {
    die($response->getError());
}
```

### Create a board

[](#create-a-board)

```
$name = 'My new board';
$optionalDescription = 'The description of the board';
$response = $api->createBoard($name, $optionalDescription);

if (!$response->ok()) {
    die($response->getError());
}

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

### Delete a board

[](#delete-a-board)

```
$boardId = '314196580192594085';
$response = $api->createBoard($boardId);

if (!$response->ok()) {
    die($response->getError());
}
```

### Create a pin

[](#create-a-pin)

```
$board = '/';
$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($board, $note, $image, $optionalLink);

if (!$response->ok()) {
    die($response->getError());
}

$pin = $response->result(); // $pin instanceof Objects\Pin
```

### Get a pin

[](#get-a-pin)

```
$pinId = 'the-pin-id';
$response = $api->getPin($pinId);

if (!$response->ok()) {
    die($response->getError());
}

$pin = $response->result(); // $pin instanceof Objects\Pin
```

### Update a pin

[](#update-a-pin)

```
// First, get the pin using getPin()

$pinId = 'the-pin-id';
$response = $api->getPin($pinId);

if (!$response->ok()) {
    die($response->getError());
}

$pin = $response->result();

// Or create a new Pin without getPin()

$pin = new Pin;
$pin->id = 'the-pin-id';

// Then, update the fields you want to change

// Update note
$pin->note = 'a new note';

// Update link
$pin->link = 'https://google.com';

$response = $api->updatePin($pin);

if (!$response->ok()) {
    die($response->getError());
}

$updatedPin = $response->result();
```

### Delete a pin

[](#delete-a-pin)

```
$pinId = 'the-pin-id';
$response = $api->deletePin($pinId);

if (!$response->ok()) {
    die($response->getError());
}
```

### 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 **hansott at hotmail be** 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

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 80.4% 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 ~67 days

Recently: every ~47 days

Total

25

Last Release

2272d ago

Major Versions

0.5.0 → 1.0.02016-03-13

1.1.1 → 2.0.02017-08-15

2.0.0 → 3.0.02017-09-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/7253049a7d2b16789d4fdf1baae498d2e67217fedbb1313a15f20d27493f4f9d?d=identicon)[hansott](/maintainers/hansott)

---

Top Contributors

[![hansott](https://avatars.githubusercontent.com/u/3886384?v=4)](https://github.com/hansott "hansott (144 commits)")[![turanct](https://avatars.githubusercontent.com/u/1728360?v=4)](https://github.com/turanct "turanct (29 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")[![SubodhDahal](https://avatars.githubusercontent.com/u/1782292?v=4)](https://github.com/SubodhDahal "SubodhDahal (2 commits)")[![narainsagar](https://avatars.githubusercontent.com/u/13800762?v=4)](https://github.com/narainsagar "narainsagar (1 commits)")[![shailesh-daund](https://avatars.githubusercontent.com/u/1464982?v=4)](https://github.com/shailesh-daund "shailesh-daund (1 commits)")

---

Tags

phppinterestpinterest-apiapioauthpinterestrepin

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/oauth2-server

A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.

6.6k136.0M248](/packages/league-oauth2-server)[auth0/auth0-php

PHP SDK for Auth0 Authentication and Management APIs.

40820.2M68](/packages/auth0-auth0-php)[auth0/symfony

Symfony SDK for Auth0 Authentication and Management APIs.

128738.1k](/packages/auth0-symfony)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

251.7M1](/packages/mollie-oauth2-mollie-php)

PHPackages © 2026

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