2017 © Pedro Peláez
 

library pinterest-api-php

PHP Wrapper for the official Pinterest API

image

dirkgroenen/pinterest-api-php

PHP Wrapper for the official Pinterest API

  • Friday, June 1, 2018
  • by dirkgroenen
  • Repository
  • 18 Watchers
  • 101 Stars
  • 117,214 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 51 Forks
  • 3 Open issues
  • 27 Versions
  • 5 % Grown

The README.md

Pinterest API - PHP

Scrutinizer Code Quality, (*1)

Packagist

A PHP wrapper for the official Pinterest API., (*2)

Requirements

  • PHP 5.4 or higher (actively tested on PHP >=7.1)
  • cURL
  • Registered Pinterest App

Get started

To use the Pinterest API you have to register yourself as a developer and create an application. After you've created your app you will receive a app_id and app_secret., (*3)

The terms client_id and client_secret are in this case app_id and app_secret., (*4)

Installation

The Pinterest API wrapper is available on Composer., (*5)

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., (*6)

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:, (*7)

$loginurl = $pinterest->auth->getLoginUrl(CALLBACK_URL, array('read_public'));
echo '<a href=' . $loginurl . '>Authorize Pinterest</a>';

Check the Pinterest documentation for the available scopes., (*8)

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:, (*9)

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

Get the user's profile

To get the profile of the current logged in user you can use the Users::me(<array>); method., (*10)

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

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., (*11)

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., (*12)

Available models

User

Pin

Board

Interest

  • id
  • name

Retrieving extra fields

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

$pinterest->users->me();

Response:, (*14)

{
    "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):, (*15)

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

The response will now be:, (*16)

{
    "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

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

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., (*18)

Available methods for the collection class:, (*19)

Get all items

all(), (*20)

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

Returns: array<Model>, (*21)

Get item at index

get( int $index ), (*22)

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

Returns: Model, (*23)

Check if collection has next page

hasNextPage(), (*24)

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

Returns: Boolean, (*25)

Get pagination data

Returns an array with an URL and cursor for the next page, or false when no next page is available., (*26)

pagination, (*27)

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

Returns: Array, (*28)

Available methods

Every method containing a data array can be filled with extra data. This can be for example extra fields or pagination., (*29)

Authentication

The methods below are available through $pinterest->auth., (*30)

Get login URL

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

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

Check the Pinterest documentation for the available scopes., (*32)

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., (*33)

Get access_token

getOAuthToken( string $code );, (*34)

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

Set access_token

setOAuthToken( string $access_token );, (*35)

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

Get state

getState();, (*36)

$pinterest->auth->getState();

Returns: string, (*37)

Set state

setState( string $state );, (*38)

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., (*39)

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

Rate limit

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

Get limit

getRateLimit();, (*41)

This method can be used to get the maximum number of requests., (*42)

$pinterest->getRateLimit();

Returns: int, (*43)

Get remaining

getRateLimitRemaining();, (*44)

This method can be used to get the remaining number of calls., (*45)

$pinterest->getRateLimitRemaining();

Returns: int, (*46)

Users

The methods below are available through $pinterest->users., (*47)

You also cannot access a user’s boards or Pins who has not authorized your app., (*48)

Get logged in user

me( array $data );, (*49)

$pinterest->users->me();

Returns: User, (*50)

Find a user

find( string $username_or_id );, (*51)

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

Returns: User, (*52)

Get user's pins

getMePins( array $data );, (*53)

$pinterest->users->getMePins();

Returns: Collection<Pin>, (*54)

Search in user's pins

getMePins( string $query, array $data );, (*55)

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

Returns: Collection<Pin>, (*56)

Search in user's boards

searchMeBoards( string $query, array $data );, (*57)

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

Returns: Collection<Board>, (*58)

Get user's boards

getMeBoards( array $data );, (*59)

$pinterest->users->getMeBoards();

Returns: Collection<Board>, (*60)

Get user's likes

getMeLikes( array $data );, (*61)

$pinterest->users->getMeLikes();

Returns: Collection<Pin>, (*62)

Get user's followers

getMeLikes( array $data );, (*63)

$pinterest->users->getMeFollowers();

Returns: Collection<Pin>, (*64)

Boards

The methods below are available through $pinterest->boards., (*65)

Get board

get( string $board_id, array $data );, (*66)

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

Returns: Board, (*67)

Create board

create( array $data );, (*68)

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

Returns: Board, (*69)

Edit board

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

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

Returns: Board, (*71)

Delete board

delete( string $board_id, array $data );, (*72)

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

Returns: True|PinterestException, (*73)

Sections

The methods below are available through $pinterest->sections., (*74)

Create section on board

create( string $board_id, array $data );, (*75)

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

Returns: Section, (*76)

Get sections on board

get( string $board_id, array $data );, (*77)

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

Returns: Collection<Section>, (*78)

Get pins from section

Note: Returned board ids can't directly be provided to pins(). The id needs to be extracted from <BoardSection xxx>, (*79)

get( string $board_id, array $data );, (*80)

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

Returns: Collection<Pin>, (*81)

Delete section

delete( string $section_id );, (*82)

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

Returns: boolean, (*83)

Pins

The methods below are available through $pinterest->pins., (*84)

Get pin

get( string $pin_id, array $data );, (*85)

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

Returns: Pin, (*86)

Get pins from board

fromBoard( string $board_id, array $data );, (*87)

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

Returns: Collection<Pin>, (*88)

Create pin

create( array $data );, (*89)

Creating a pin with an image hosted somewhere else:, (*90)

$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:, (*91)

$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:, (*92)

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

Returns: Pin, (*93)

Edit pin

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

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

Returns: Pin, (*95)

Delete pin

delete( string $pin_id, array $data );, (*96)

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

Returns: True|PinterestException, (*97)

Following

The methods below are available through $pinterest->following., (*98)

Following users

users( array $data );, (*99)

$pinterest->following->users();

Returns: Collection<User>, (*100)

Following boards

boards( array $data );, (*101)

$pinterest->following->boards();

Returns: Collection<Board>, (*102)

Following interests/categories

interests( array $data );, (*103)

$pinterest->following->interests();

Returns: Collection<Interest>, (*104)

Follow an user

followUser( string $username_or_id );, (*105)

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

Returns: True|PinterestException, (*106)

Unfollow an user

unfollowUser( string $username_or_id );, (*107)

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

Returns: True|PinterestException, (*108)

Follow a board

followBoard( string $board_id );, (*109)

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

Returns: True|PinterestException, (*110)

Unfollow a board

unfollowBoard( string $board_id );, (*111)

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

Returns: True|PinterestException, (*112)

Follow an interest

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

followInterest( string $interest );, (*114)

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

Returns: True|PinterestException, (*115)

Unfollow an interest

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

unfollowInterest( string $interest );, (*117)

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

Returns: True|PinterestException, (*118)

Examples

Use can take a look at the ./demo directory for a simple example., (*119)

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

The Versions

01/06 2018

dev-development

dev-development

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api wrapper pinterest

01/06 2018

dev-master

9999999-dev

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api wrapper pinterest

10/05 2016

0.2.11

0.2.11.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

11/02 2016

0.2.10

0.2.10.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

10/02 2016

0.2.9

0.2.9.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

10/02 2016

dev-scrutinizer-patch-6

dev-scrutinizer-patch-6

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

02/02 2016

dev-scrutinizer-patch-5

dev-scrutinizer-patch-5

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

02/02 2016

0.2.8

0.2.8.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

01/02 2016

0.2.7

0.2.7.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

01/02 2016

dev-scrutinizer-patch-4

dev-scrutinizer-patch-4

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

01/02 2016

dev-scrutinizer-patch-3

dev-scrutinizer-patch-3

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

01/02 2016

0.2.6

0.2.6.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

09/01 2016

dev-scrutinizer-patch-2

dev-scrutinizer-patch-2

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

09/01 2016

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

09/01 2016

0.2.5

0.2.5.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

06/01 2016

0.2.4

0.2.4.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

03/01 2016

0.2.3

0.2.3.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4

 

The Development Requires

api wrapper pinterest

31/12 2015

0.2.2

0.2.2.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api wrapper pinterest

23/12 2015

0.2.1

0.2.1.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api wrapper pinterest

18/12 2015

0.2.0

0.2.0.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api wrapper pinterest

14/12 2015

0.1.6

0.1.6.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api wrapper pinterest

14/12 2015

0.1.5

0.1.5.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api wrapper pinterest

11/12 2015

0.1.4

0.1.4.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api wrapper pinterest

28/11 2015

0.1.3

0.1.3.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api wrapper pinterest

16/11 2015

0.1.2

0.1.2.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api wrapper pinterest

14/10 2015

0.1.1

0.1.1.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api wrapper pinterest

06/08 2015

0.1.0

0.1.0.0

PHP Wrapper for the official Pinterest API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api wrapper pinterest