PHPackages                             dirkgroenen/pinterest-api-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. [API Development](/categories/api)
4. /
5. dirkgroenen/pinterest-api-php

ActiveLibrary[API Development](/categories/api)

dirkgroenen/pinterest-api-php
=============================

PHP Wrapper for the official Pinterest API

0.2.14(4y ago)175500.9k↓41.3%76[5 issues](https://github.com/dirkgroenen/Pinterest-API-PHP/issues)4Apache-2.0PHPPHP &gt;=5.4CI failing

Since Aug 6Pushed 4y ago18 watchersCompare

[ Source](https://github.com/dirkgroenen/Pinterest-API-PHP)[ Packagist](https://packagist.org/packages/dirkgroenen/pinterest-api-php)[ RSS](/packages/dirkgroenen-pinterest-api-php/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (2)Versions (36)Used By (4)

[![](https://camo.githubusercontent.com/70d6b255afdd04c62d3df2a176bb69f0f492c97785abbde7669ccb4817111fd4/687474703a2f2f692e696d6775722e636f6d2f63616367516c712e706e67)](https://camo.githubusercontent.com/70d6b255afdd04c62d3df2a176bb69f0f492c97785abbde7669ccb4817111fd4/687474703a2f2f692e696d6775722e636f6d2f63616367516c712e706e67) Pinterest API - PHP
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#--pinterest-api---php)

[![](https://camo.githubusercontent.com/fb011a920eb153b5762dd4e5a9d0266e773a4ba16106117d0c036aad05694fbe/68747470733a2f2f7472617669732d63692e6f72672f6469726b67726f656e656e2f50696e7465726573742d4150492d5048502e737667)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP)[![](https://camo.githubusercontent.com/aacf8c51c69ea734c68d653719914ec55f42c7865bd4ee006fa6ba9f47374947/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6469726b67726f656e656e2f50696e7465726573742d4150492d5048502e737667)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master)[![](https://camo.githubusercontent.com/d2c3fbaa92522e5dcdbf2b7e3ef0bf0d4194114da15107166fb336afa97f31bc/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6469726b67726f656e656e2f50696e7465726573742d4150492d5048502e737667)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/17c808c53621f30b1e96e64a500106113de99b9e1188593bf5646821128875be/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6469726b67726f656e656e2f50696e7465726573742d4150492d5048502f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master)[![Packagist](https://camo.githubusercontent.com/66223bd60d59914da314a4fd22d1c23585e7317738942109f9926863e958b62c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6469726b67726f656e656e2f70696e7465726573742d6170692d7068702e737667)](https://packagist.org/packages/dirkgroenen/pinterest-api-php)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#)

A PHP wrapper for the official [Pinterest API](https://dev.pinterest.com).

Requirements
============

[](#requirements)

- PHP 5.4 or higher (actively tested on PHP &gt;=7.1)
- cURL
- Registered Pinterest App

Get started
===========

[](#get-started)

To use the Pinterest API you have to register yourself as a developer and [create](https://dev.pinterest.com/apps/) an application. After you've created your app you will receive a `app_id` and `app_secret`.

> The terms `client_id` and `client_secret` are in this case `app_id` and `app_secret`.

Installation
------------

[](#installation)

The Pinterest API wrapper is available on Composer.

```
composer require dirkgroenen/pinterest-api-php

```

If you're not using Composer (which you should start using, unless you've got a good reason not to) you can include the `autoload.php` file in your project.

Simple Example
--------------

[](#simple-example)

```
use DirkGroenen\Pinterest\Pinterest;

$pinterest = new Pinterest(CLIENT_ID, CLIENT_SECRET);
```

After you have initialized the class you can get a login URL:

```
$loginurl = $pinterest->auth->getLoginUrl(CALLBACK_URL, array('read_public'));
echo 'Authorize Pinterest';
```

Check the [Pinterest documentation](https://dev.pinterest.com/docs/api/overview/#scopes) for the available scopes.

After your user has used the login link to authorize he will be send back to the given `CALLBACK_URL`. The URL will contain the `code` which can be exchanged into an `access_token`. To exchange the code for an `access_token` and set it you can use the following code:

```
if(isset($_GET["code"])){
    $token = $pinterest->auth->getOAuthToken($_GET["code"]);
    $pinterest->auth->setOAuthToken($token->access_token);
}
```

Get the user's profile
----------------------

[](#get-the-users-profile)

To get the profile of the current logged in user you can use the `Users::me();` method.

```
$me = $pinterest->users->me();
echo $me;
```

Models
======

[](#models)

The API wrapper will parse all data through it's corresponding model. This results in the possibility to (for example) directly `echo` your model into a JSON string.

Models also show the available fields (which are also described in the Pinterest documentation). By default, not all fields are returned, so this can help you when providing extra fields to the request.

Available models
----------------

[](#available-models)

### [User](https://dev.pinterest.com/docs/api/users/#user-object)

[](#user)

### [Pin](https://dev.pinterest.com/docs/api/pins/#pin-object)

[](#pin)

### [Board](https://dev.pinterest.com/docs/api/boards/#board-object)

[](#board)

### Interest

[](#interest)

- id
- name

Retrieving extra fields
-----------------------

[](#retrieving-extra-fields)

If you want more fields you can specify these in the `$data` (GET requests) or `$fields` (PATCH requests) array. Example:

```
$pinterest->users->me();
```

Response:

```
{
    "id": "503066358284560467",
    "username": null,
    "first_name": "Dirk ",
    "last_name": "Groenen",
    "bio": null,
    "created_at": null,
    "counts": null,
    "image": null
}
```

By default, not all fields are returned. The returned data from the API has been parsed into the `User` model. Every field in this model can be filled by parsing an extra `$data` array with the key `fields`. Say we want the user's username, first\_name, last\_name and image (small and large):

```
$pinterest->users->me(array(
    'fields' => 'username,first_name,last_name,image[small,large]'
));
```

The response will now be:

```
{
    "id": "503066358284560467",
    "username": "dirkgroenen",
    "first_name": "Dirk ",
    "last_name": "Groenen",
    "bio": null,
    "created_at": null,
    "counts": null,
    "image": {
        "small": {
                "url": "http://media-cache-ak0.pinimg.com/avatars/dirkgroenen_1438089829_30.jpg",
                "width": 30,
                "height": 30
            },
            "large": {
                "url": "http://media-cache-ak0.pinimg.com/avatars/dirkgroenen_1438089829_280.jpg",
                "width": 280,
                "height": 280
            }
        }
    }
}
```

Collection
==========

[](#collection)

When the API returns multiple models (for instance when your requesting the pins from a board) the wrapper will put those into a `Collection`.

The output of a collection contains the `data` and page `key`. If you echo the collection you will see a json encoded output containing both of these. Using the collection as an array will only return the items from `data`.

Available methods for the collection class:

Get all items
-------------

[](#get-all-items)

`all()`

```
$pins = $pinterest->users->getMeLikes();
$pins->all();
```

Returns: `array`

Get item at index
-----------------

[](#get-item-at-index)

`get( int $index )`

```
$pins = $pinterest->users->getMeLikes();
$pins->get(0);
```

Returns: `Model`

Check if collection has next page
---------------------------------

[](#check-if-collection-has-next-page)

`hasNextPage()`

```
$pins = $pinterest->users->getMeLikes();
$pins->hasNextPage();
```

Returns: `Boolean`

Get pagination data
-------------------

[](#get-pagination-data)

Returns an array with an `URL` and `cursor` for the next page, or `false` when no next page is available.

`pagination`

```
$pins = $pinterest->users->getMeLikes();
$pins->pagination['cursor'];
```

Returns: `Array`

Available methods
=================

[](#available-methods)

> Every method containing a `data` array can be filled with extra data. This can be for example extra fields or pagination.

Authentication
--------------

[](#authentication)

The methods below are available through `$pinterest->auth`.

### Get login URL

[](#get-login-url)

`getLoginUrl(string $redirect_uri, array $scopes, string $response_type = "code");`

```
$pinterest->auth->getLoginUrl("https://pinterest.dev/callback.php", array("read_public"));
```

Check the [Pinterest documentation](https://dev.pinterest.com/docs/api/overview/#scopes) for the available scopes.

**Note: since 0.2.0 the default authentication method has changed to `code` instead of `token`. This means you have to exchange the returned code for an access\_token.**

### Get access\_token

[](#get-access_token)

`getOAuthToken( string $code );`

```
$pinterest->auth->getOAuthToken($code);
```

### Set access\_token

[](#set-access_token)

`setOAuthToken( string $access_token );`

```
$pinterest->auth->setOAuthToken($access_token);
```

### Get state

[](#get-state)

`getState();`

```
$pinterest->auth->getState();
```

Returns: `string`

### Set state

[](#set-state)

`setState( string $state );`

This method can be used to set a state manually, but this isn't required since the API will automatically generate a random state on initialize.

```
$pinterest->auth->setState($state);
```

Rate limit
----------

[](#rate-limit)

> Note that you should call an endpoint first, otherwise `getRateLimit()` will return `unknown`.

### Get limit

[](#get-limit)

`getRateLimit();`

This method can be used to get the maximum number of requests.

```
$pinterest->getRateLimit();
```

Returns: `int`

### Get remaining

[](#get-remaining)

`getRateLimitRemaining();`

This method can be used to get the remaining number of calls.

```
$pinterest->getRateLimitRemaining();
```

Returns: `int`

Users
-----

[](#users)

The methods below are available through `$pinterest->users`.

> You also cannot access a user’s boards or Pins who has not authorized your app.

### Get logged in user

[](#get-logged-in-user)

`me( array $data );`

```
$pinterest->users->me();
```

Returns: `User`

### Find a user

[](#find-a-user)

`find( string $username_or_id );`

```
$pinterest->users->find('dirkgroenen');
```

Returns: `User`

### Get user's pins

[](#get-users-pins)

`getMePins( array $data );`

```
$pinterest->users->getMePins();
```

Returns: `Collection`

### Search in user's pins

[](#search-in-users-pins)

`getMePins( string $query, array $data );`

```
$pinterest->users->searchMePins("cats");
```

Returns: `Collection`

### Search in user's boards

[](#search-in-users-boards)

`searchMeBoards( string $query, array $data );`

```
$pinterest->users->searchMeBoards("cats");
```

Returns: `Collection`

### Get user's boards

[](#get-users-boards)

`getMeBoards( array $data );`

```
$pinterest->users->getMeBoards();
```

Returns: `Collection`

### Get user's likes

[](#get-users-likes)

`getMeLikes( array $data );`

```
$pinterest->users->getMeLikes();
```

Returns: `Collection`

### Get user's followers

[](#get-users-followers)

`getMeLikes( array $data );`

```
$pinterest->users->getMeFollowers();
```

Returns: `Collection`

Boards
------

[](#boards)

The methods below are available through `$pinterest->boards`.

### Get board

[](#get-board)

`get( string $board_id, array $data );`

```
$pinterest->boards->get("dirkgroenen/pinterest-api-test");
```

Returns: `Board`

### Create board

[](#create-board)

`create( array $data );`

```
$pinterest->boards->create(array(
    "name"          => "Test board from API",
    "description"   => "Test Board From API Test"
));
```

Returns: `Board`

### Edit board

[](#edit-board)

`edit( string $board_id, array $data, string $fields = null );`

```
$pinterest->boards-edit("dirkgroenen/pinterest-api-test", array(
    "name"  => "Test board after edit"
));
```

Returns: `Board`

### Delete board

[](#delete-board)

`delete( string $board_id, array $data );`

```
$pinterest->boards->delete("dirkgroenen/pinterest-api-test");
```

Returns: `True|PinterestException`

Sections
--------

[](#sections)

The methods below are available through `$pinterest->sections`.

### Create section on board

[](#create-section-on-board)

`create( string $board_id, array $data );`

```
$pinterest->sections->create("503066289565421205", array(
    "title" => "Test from API"
));
```

Returns: `Section`

### Get sections on board

[](#get-sections-on-board)

`get( string $board_id, array $data );`

```
$pinterest->sections->get("503066289565421205");
```

Returns: `Collection`

### Get pins from section

[](#get-pins-from-section)

> Note: Returned board ids can't directly be provided to `pins()`. The id needs to be extracted from &lt;BoardSection xxx&gt;

`get( string $board_id, array $data );`

```
$pinterest->sections->pins("5027630990032422748");
```

Returns: `Collection`

### Delete section

[](#delete-section)

`delete( string $section_id );`

```
$pinterest->sections->delete("5027630990032422748");
```

Returns: `boolean`

Pins
----

[](#pins)

The methods below are available through `$pinterest->pins`.

### Get pin

[](#get-pin)

`get( string $pin_id, array $data );`

```
$pinterest->pins->get("181692166190246650");
```

Returns: `Pin`

### Get pins from board

[](#get-pins-from-board)

`fromBoard( string $board_id, array $data );`

```
$pinterest->pins->fromBoard("dirkgroenen/pinterest-api-test");
```

Returns: `Collection`

### Create pin

[](#create-pin)

`create( array $data );`

Creating a pin with an image hosted somewhere else:

```
$pinterest->pins->create(array(
    "note"          => "Test board from API",
    "image_url"     => "https://download.unsplash.com/photo-1438216983993-cdcd7dea84ce",
    "board"         => "dirkgroenen/pinterest-api-test"
));
```

Creating a pin with an image located on the server:

```
$pinterest->pins->create(array(
    "note"          => "Test board from API",
    "image"         => "/path/to/image.png",
    "board"         => "dirkgroenen/pinterest-api-test"
));
```

Creating a pin with a base64 encoded image:

```
$pinterest->pins->create(array(
    "note"          => "Test board from API",
    "image_base64"  => "[base64 encoded image]",
    "board"         => "dirkgroenen/pinterest-api-test"
));
```

Returns: `Pin`

### Edit pin

[](#edit-pin)

`edit( string $pin_id, array $data, string $fields = null );`

```
$pinterest->pins->edit("181692166190246650", array(
    "note"  => "Updated name"
));
```

Returns: `Pin`

### Delete pin

[](#delete-pin)

`delete( string $pin_id, array $data );`

```
$pinterest->pins->delete("181692166190246650");
```

Returns: `True|PinterestException`

Following
---------

[](#following)

The methods below are available through `$pinterest->following`.

### Following users

[](#following-users)

`users( array $data );`

```
$pinterest->following->users();
```

Returns: `Collection`

### Following boards

[](#following-boards)

`boards( array $data );`

```
$pinterest->following->boards();
```

Returns: `Collection`

### Following interests/categories

[](#following-interestscategories)

`interests( array $data );`

```
$pinterest->following->interests();
```

Returns: `Collection`

### Follow an user

[](#follow-an-user)

`followUser( string $username_or_id );`

```
$pinterest->following->followUser("dirkgroenen");
```

Returns: `True|PinterestException`

### Unfollow an user

[](#unfollow-an-user)

`unfollowUser( string $username_or_id );`

```
$pinterest->following->unfollowUser("dirkgroenen");
```

Returns: `True|PinterestException`

### Follow a board

[](#follow-a-board)

`followBoard( string $board_id );`

```
$pinterest->following->followBoard("503066289565421201");
```

Returns: `True|PinterestException`

### Unfollow a board

[](#unfollow-a-board)

`unfollowBoard( string $board_id );`

```
$pinterest->following->unfollowBoard("503066289565421201");
```

Returns: `True|PinterestException`

### Follow an interest

[](#follow-an-interest)

> According to the Pinterest documentation this endpoint exists, but for some reason their API is returning an error at the moment.

`followInterest( string $interest );`

```
$pinterest->following->followInterest("architecten-911112299766");
```

Returns: `True|PinterestException`

### Unfollow an interest

[](#unfollow-an-interest)

> According to the Pinterest documentation this endpoint exists, but for some reason their API is returning an error at the moment.

`unfollowInterest( string $interest );`

```
$pinterest->following->unfollowInterest("architecten-911112299766");
```

Returns: `True|PinterestException`

Examples
========

[](#examples)

Use can take a look at the `./demo` directory for a simple example.

Let me know if you have an (example) project using the this library.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity54

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 81.2% 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 ~105 days

Recently: every ~508 days

Total

22

Last Release

1759d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ca4a380fd999c405dbc11c6c4ea19cb5a61aa75db632ba916456811ece82be6c?d=identicon)[dirkgroenen](/maintainers/dirkgroenen)

---

Top Contributors

[![dirkgroenen](https://avatars.githubusercontent.com/u/1001391?v=4)](https://github.com/dirkgroenen "dirkgroenen (147 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (6 commits)")[![pavelhouzva](https://avatars.githubusercontent.com/u/4955758?v=4)](https://github.com/pavelhouzva "pavelhouzva (5 commits)")[![aimflaiims](https://avatars.githubusercontent.com/u/17019518?v=4)](https://github.com/aimflaiims "aimflaiims (3 commits)")[![mikropiks](https://avatars.githubusercontent.com/u/47701642?v=4)](https://github.com/mikropiks "mikropiks (3 commits)")[![bercium](https://avatars.githubusercontent.com/u/909988?v=4)](https://github.com/bercium "bercium (3 commits)")[![sfai05](https://avatars.githubusercontent.com/u/1597348?v=4)](https://github.com/sfai05 "sfai05 (2 commits)")[![itzmukeshy7](https://avatars.githubusercontent.com/u/5780768?v=4)](https://github.com/itzmukeshy7 "itzmukeshy7 (2 commits)")[![nWidart](https://avatars.githubusercontent.com/u/882397?v=4)](https://github.com/nWidart "nWidart (2 commits)")[![kapunakap](https://avatars.githubusercontent.com/u/1783732?v=4)](https://github.com/kapunakap "kapunakap (1 commits)")[![martinstuecklschwaiger](https://avatars.githubusercontent.com/u/1061218?v=4)](https://github.com/martinstuecklschwaiger "martinstuecklschwaiger (1 commits)")[![jamesinealing](https://avatars.githubusercontent.com/u/1590569?v=4)](https://github.com/jamesinealing "jamesinealing (1 commits)")[![NinoSkopac](https://avatars.githubusercontent.com/u/1783732?v=4)](https://github.com/NinoSkopac "NinoSkopac (1 commits)")[![baddiv12](https://avatars.githubusercontent.com/u/56021633?v=4)](https://github.com/baddiv12 "baddiv12 (1 commits)")[![ishikawam](https://avatars.githubusercontent.com/u/1132355?v=4)](https://github.com/ishikawam "ishikawam (1 commits)")[![gpopoteur](https://avatars.githubusercontent.com/u/952557?v=4)](https://github.com/gpopoteur "gpopoteur (1 commits)")[![kalenjohnson](https://avatars.githubusercontent.com/u/2036520?v=4)](https://github.com/kalenjohnson "kalenjohnson (1 commits)")

---

Tags

api-wrapperphppinterestpinterest-apiapiwrapperpinterest

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[gabrielbull/ups-api

PHP UPS API

4572.4M11](/packages/gabrielbull-ups-api)[wtfzdotnet/php-tmdb-api

PHP wrapper for TMDB (TheMovieDatabase) API v3. Supports two types of approaches, one modelled with repositories, models and factories. And the other by simple array access to RAW data from The Movie Database.

4262.9k](/packages/wtfzdotnet-php-tmdb-api)[walle89/swedbank-json

Unofficial API client for the Swedbank's and Sparbanken's mobile apps in Sweden.

782.5k](/packages/walle89-swedbank-json)

PHPackages © 2026

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