Giter Club home page Giter Club logo

pinterest-api-php's Introduction

Pinterest API - PHP

Scrutinizer Code Quality Packagist

A PHP wrapper for the official Pinterest API.

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.

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

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

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 '<a href=' . $loginurl . '>Authorize Pinterest</a>';

Check the Pinterest documentation 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

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

$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.

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

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:

$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

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

all()

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

Returns: array<Model>

Get item at index

get( int $index )

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

Returns: Model

Check if collection has next page

hasNextPage()

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

Returns: Boolean

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

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

Authentication

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

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

getOAuthToken( string $code );

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

Set access_token

setOAuthToken( string $access_token );

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

Get state

getState();

$pinterest->auth->getState();

Returns: string

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

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

Get limit

getRateLimit();

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

$pinterest->getRateLimit();

Returns: int

Get remaining

getRateLimitRemaining();

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

$pinterest->getRateLimitRemaining();

Returns: int

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

me( array $data );

$pinterest->users->me();

Returns: User

Find a user

find( string $username_or_id );

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

Returns: User

Get user's pins

getMePins( array $data );

$pinterest->users->getMePins();

Returns: Collection<Pin>

Search in user's pins

getMePins( string $query, array $data );

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

Returns: Collection<Pin>

Search in user's boards

searchMeBoards( string $query, array $data );

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

Returns: Collection<Board>

Get user's boards

getMeBoards( array $data );

$pinterest->users->getMeBoards();

Returns: Collection<Board>

Get user's likes

getMeLikes( array $data );

$pinterest->users->getMeLikes();

Returns: Collection<Pin>

Get user's followers

getMeLikes( array $data );

$pinterest->users->getMeFollowers();

Returns: Collection<Pin>

Boards

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

Get board

get( string $board_id, array $data );

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

Returns: 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( 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( string $board_id, array $data );

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

Returns: True|PinterestException

Sections

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

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( string $board_id, array $data );

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

Returns: Collection<Section>

Get pins from section

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

get( string $board_id, array $data );

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

Returns: Collection<Pin>

Delete section

delete( string $section_id );

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

Returns: boolean

Pins

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

Get pin

get( string $pin_id, array $data );

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

Returns: Pin

Get pins from board

fromBoard( string $board_id, array $data );

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

Returns: Collection<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( string $pin_id, array $data, string $fields = null );

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

Returns: Pin

Delete pin

delete( string $pin_id, array $data );

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

Returns: True|PinterestException

Following

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

Following users

users( array $data );

$pinterest->following->users();

Returns: Collection<User>

Following boards

boards( array $data );

$pinterest->following->boards();

Returns: Collection<Board>

Following interests/categories

interests( array $data );

$pinterest->following->interests();

Returns: Collection<Interest>

Follow an user

followUser( string $username_or_id );

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

Returns: True|PinterestException

Unfollow an user

unfollowUser( string $username_or_id );

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

Returns: True|PinterestException

Follow a board

followBoard( string $board_id );

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

Returns: True|PinterestException

Unfollow a board

unfollowBoard( string $board_id );

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

Returns: True|PinterestException

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

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

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.

pinterest-api-php's People

Contributors

aimflaiims avatar baddiv12 avatar bercium avatar dirkgroenen avatar gpopoteur avatar ishikawam avatar itzmukeshy7 avatar jamesinealing avatar kalenjohnson avatar martinstuecklschwaiger avatar mikropiks avatar ninoskopac avatar nwidart avatar pavelhouzva avatar scrutinizer-auto-fixer avatar sfai05 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pinterest-api-php's Issues

Any way to ignore a fatal error when creating a pin

Firstly, what an outstanding piece of code you have here. Thank you for piecing this together so that I don't have to!

When creating a pin, if the image URL leads to a 404 page, then we receive a fatal error. Is it possible to adjust the code so that it is not a fatal error which essentially stops the rest of the PHP code from running.

You can simply try it using an image URL that doesn't exist.

You will receive the following error:

Fatal error: Uncaught exception 'DirkGroenen\Pinterest\Exceptions\PinterestException' with message 'Pinterest error (code: 400) with message: Sorry we could not fetch the image.

in /Pinterest-API-PHP/src/Pinterest/Transport/Request.php:233 Stack trace: #0

When I am trying to change the code to an access token, I get this error

Notice: Array to string conversion in /home/socialwe/public_html/SWT/SMs/pinterestApi/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php on line 227

Fatal error: Uncaught exception 'DirkGroenen\Pinterest\Exceptions\PinterestException' with message 'Pinterest error (code: 403) with message: Forbidden' in /home/socialwe/public_html/SWT/SMs/pinterestApi/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php:227 Stack trace: #0 /home/socialwe/public_html/SWT/SMs/pinterestApi/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php(98): DirkGroenen\Pinterest\Transport\Request->execute('POST', 'https://api.pin...', Array) #1 /home/socialwe/public_html/SWT/SMs/pinterestApi/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Auth/PinterestOAuth.php(143): DirkGroenen\Pinterest\Transport\Request->post('oauth/token', Array) #2 /home/socialwe/public_html/SWT/SMs/pinterestApi/index.php(18): DirkGroenen\Pinterest\Auth\PinterestOAuth->getOAuthToken('dfb587ef87beaaa...') #3 {main} thrown in /home/socialwe/public_html/SWT/SMs/pinterestApi/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php on line 227

Pinterest error (code: 400) with message: Parameter 'board' is required.

('POST', 'https://api.pinterest.com/v1/pins', array('image_url' => 'http://tld.com/6b2d6ce3401d3b2cc4f8de5852796a0229645789.jpeg', 'note' => 'test', 'link' => 'http://tld.com/072AE601DF7DB00445386F5C9CC46F74', 'board' => 'username/myboardname')

got this recently, work before...i just update my project with composer update

Should have different error for empty response than error response

At present, in Pinterest/Transport/Request.php, line 211-212, you raise an error for empty response with the same block of code as an error response. With that setup, the empty response is hard to identify in order to be handled appropriately in apps using this library. Would it be possible to adjust this bit to return an identifiable error code for empty responses? Thanks!

update pin not working

Hi,
I see in your documentation that you couldn't get it to work either. However it works through the API Explorer: https://developers.pinterest.com/tools/api-explorer/

I keep getting the error:
Pinterest error (code: 500) with message: cannot concatenate 'str' and 'NoneType' objects'

The fact that it works through the Explorer (and affects live data) seems like maybe it's an issue with your code.

Thanks.

Image upload is not working

I don't know what's broken but it is definitely not working. I have tested it with image_url to make sure there is nothing wrong with my code.

Notice: Undefined variable: CURLOPT_MAXREDIRS

Hello. Thanks for nice lib!
I have noticed the error in a code:
Notice: Undefined variable: CURLOPT_MAXREDIRS in .../Pinterest/Utils/CurlBuilder.php on line 194. You need to change
if ($CURLOPT_MAXREDIRS > 0) {
to
if (CURLOPT_MAXREDIRS > 0) {
(just remove $ sign before CURLOPT). Thanks!

403 error when trying to Pin using token

PHP Fatal error: Uncaught exception 'DirkGroenen\Pinterest\Exceptions\PinterestException' with message 'Pinterest error (code: 403) with message: Forbidden' in /home/customer/pino/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php:227
Stack trace:
#0 /home/customer/pino/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php(98): DirkGroenen\Pinterest\Transport\Request->execute('POST', 'https://api.pin...', Array)
#1 /home/customer/pino/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Endpoints/Pins.php(66): DirkGroenen\Pinterest\Transport\Request->post('pins', Array)
#2 /home/customer/pino/index.php(18): DirkGroenen\Pinterest\Endpoints\Pins->create(Array)
#3 {main}

thrown in /home/customer/pino/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php on line 227

Fatal error: Uncaught exception 'DirkGroenen\Pinterest\Exceptions\PinterestException' with message 'Pinterest error (code: 403) with message: Forbidden' in /home/customer/pino/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php:227
Stack trace:
#0 /home/customer/pino/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php(98): DirkGroenen\Pinterest\Transport\Request->execute('POST', 'https://api.pin...', Array)
#1 /home/customer/pino/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Endpoints/Pins.php(66): DirkGroenen\Pinterest\Transport\Request->post('pins', Array)
#2 /home/customer/pino/index.php(18): DirkGroenen\Pinterest\Endpoints\Pins->create(Array)
#3 {main}

thrown in /home/customer/pino/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php on line 227

How can I check if my token is still valid?

i have read the docs, and checked the code.

I dont see any way to validate that a stored token is still valid.
Pinterest has a tool on their dev site for token debugger, but dont see it in the api.

Am I missing something here.

I would like to check to make sure that the token i have is still valid, using this api.

Autoload in index.php file

Hello. I want to advice you to add to the examples, for example to index.php file which is in the root of the site next code to autoload all the classes:

404 Error

Hey,

I have added some code to create the board and I got the following error every time,

Fatal error: Uncaught exception 'DirkGroenen\Pinterest\Exceptions\PinterestException' with message 'Pinterest error (code: 404) with message: Board not found.'

$pin_board = $pinterest->boards->create(array(
    "name"          => "Name",
    "description"   => "Description",
    "creator"   => "",

));

Can you please help me?

Errors in curlbuilder, inc infinite loop

I had lots of problems getting things to work on my staging server (turned out to be because CURLfile couldn't fetch remove URLs, only local files). It took hours of debugging, because the curlbuilder class never returns the curl error.

In the process, I found several things that needed changing to make things work for me:

  1. ini_get("safe_mode" == "Off") has a code typo - should have been ini_get("safe_mode") == "Off"
    However, on some systems it returns "" (and safe_mode is deprecated now anyway:

BEFORE
if (ini_get("open_basedir") == "" && ini_get("safe_mode" == "Off")) {
AFTER

if (filter_var(ini_get('open_basedir'), FILTER_VALIDATE_BOOLEAN) === false 
&& filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN) === false) {
  1. Headers aren't sent again on followlocation, so I added an undocumented CURLOPT_POSTREDIR => 3 to make sure we send POST headers again if redirected
    https://evertpot.com/curl-redirect-requestbody/
CURLOPT_FOLLOWLOCATION => $mr > 0,
CURLOPT_MAXREDIRS => $mr
,CURLOPT_POSTREDIR => 3 // CUSTOM-ADDED - otherwise the POST headers aren't set after redirect
  1. if we do use FOLLOWLOCATION, it just sets some curl options, but doesn't set $body. It then drops into the code below which calls ->execute() again, which will do exactly the same in an infinite loop, never actually calling curl_exec()
{
   $this->setOption(CURLOPT_HEADER, true);
//   $response = $this->execute(); // CUSTOM-REMOVED - this just calls the curlbuilder->execute again and again forever
   $response = curl_exec($this->curl); // CUSTOM-ADDED - use this instead
  1. Would be really useful to catch any curl errors in curlbuilder and return them.

paging

Thanks for this API client. ;) I was used to webscrap data previously ...
I've noticed an issue about the page property, it's always set to false even if pinterest send the data correctly.

In the Collection class line 90, if I replace the

if( is_set($this->response->page) && !empty($this->response->page['next']) ){

by

if( is_array($this->response->page) && !empty($this->response->page['next']) ){

it does the trick.
The is_set always return false, weird. I'm using PHP 5.5.30.

Followers Data of Users

How can i get list of followers of a user with their username,
this user is not the authenticated user

Undefined variable $CURLOPT_MAXREDIRS

Hi.
class: /src/Pinterest/Utils/CurlBuilder.php
method: private function execFollow()
line: 194
You are using variable $CURLOPT_MAXREDIRS but it is not defined before using.

Warning About autoload.php

Hey,

I have added your API with the Core PHP and make the Request to get the Login URL and then after access the token based on the code.

But I got the following errors,

Warning: require(../vendor/autoload.php): failed to open stream: No such file or directory in

Can you please help me asap?

Board is created but an exception is returned

Hello!

I'm trying to create a board and pin an item inside of it. Here's my code:

try {
	$board_name = 'myapp';
	$createboard_response = $pinterest->boards->create([
		"name" => $board_name,
		"description" => 'my desc'
	]);

	if($createboard_response){
		
		try {
			$createpin_response = $pinterest->pins->create([
			    "note" => $pinterest_pin_text,
			    "image_url" => 'http://somelink.com/toimage.png',
			    "link" => 'http://someurl.com',
			    "board" => "{$pinterest_user->username}/{$board_name}"
			]);

			print_r($createpin_response);

		} catch (\DirkGroenen\Pinterest\Exceptions\PinterestException $e) {
			return $e->getMessage();
		}

	}
} catch (\DirkGroenen\Pinterest\Exceptions\PinterestException $e) {
	return $e->getMessage();
}

The creation of board succeeds, and I can see it in my pinterest profile, but the library returns the following exception:

Pinterest error (code: 500) with message: "{\"user_id\": 461xxxxxxxxxxx, \"collaborator_invites_enabled\": false, \"description\": \"my desc\", \"private\": false, \"protected\": false, \"layout\": 0, \"slug\": \"myapp\", \"name\": \"myapp\"}"

Which means that the code for creating the pin inside the board that was just created won't event get executed. Any ideas? I don't really want to skip the try catch because there might be legit errors later on.

too many values to unpack Error

I am receiving error "Pinterest error (code: 500) with message: too many values to unpack", when trying to create a pin using pins->create()

Pinterest error (code: 401) with message: Authorization failed

Hi Still new to Pinterest API, btw loving your work on this PHP wrapper for Pinterest API.
I always get this error when I create pins on my board.

" Pinterest error (code: 401) with message: Authorization failed "

I just copy your code to test

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

The board is already existing on my account and when I run this code:
$me = $pinterest->users->me();
echo $me;

it works fine, I already got my Access Token, I don't know what really the problem is or does it matter if the app is still "In development"? Thanks hope to hear from you soon

NOTE: sorry about this issue was able to fixed it please ignore.

Undefined index: message in Response

Hello,

I'm using the latest version on this package, and since last time I see there were some changes. Ie: the token isn't returned directly.

Instead a code is returned, and we need to get the token from that, if I understand it correctly.

However the following code gives this error:

$authToken = $this->pinterest->auth->getOAuthToken($code);
ErrorException in /home/vagrant/liftmetrixapp/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Response.php line 70:
Undefined index: message

Did I miss something ?

Thank you.

boards->create function issues

The following:

$board = $pinterest->boards->create(array(
    "name"          => "Bla Bla"
));

returns an object like this and no board get created:
{"id":null,"name":null,"url":null,"description":null,"creator":null,"created_at":null,"counts":null,"image":null}

Exceptions: message/code are protected

Hi and thanks you for this nice piece of code !
I would like to be able to display errors when the API request fails; but the message and code returned by the exception are protected. Is this possible ?

            try{
                $json = pinim()->api->users->me(array('fields' => 'username,first_name,last_name,image[large],counts'));
                $userdatas = json_decode($json, true);
            }catch (Exception $e) {
                            //get exception message or code here ?
            }

Because for now, when I try to access $e->message, it fires:

Fatal error: Uncaught Error: Cannot access protected property DirkGroenen\Pinterest\Exceptions\PinterestException::$message in ...

Updated getOauthToken

Pinterest have finally decided on the oauth access token behaviour - the only thing that needs adding to the getOauthToken function in PinterestOauth.php is "timesatmp" => time(),:

public function getOAuthToken($code)
    {
        // Build data array
        $data = array(
            "grant_type"    => "authorization_code",
            "client_id"     => $this->client_id,
            "client_secret" => $this->client_secret,
            "timestamp"     => time(),
            "code"          => $code
        );

        // Perform post request
        $response = $this->request->post("oauth/token", $data);

        return $response;
    }

users->getMeBoards() brings "Undefined index: page"

Hi there!
Currently Pinterest API response doesn't have a 'page' value.
There is only a 'data' field in response, and it is stated here:
/pinterest-api-php/tests/Pinterest/responses/UsersTest/testGetMeBoards.json

In collection.php:90 there is
// Add pagination object
$this->pagination = $this->response->page;

It makes /Transport/Response.php:70 answering
Undefined index: page

thanks

Feature request: Get/Set the scope

Hi,

Is there any chance that you can add the ability to get the generated state or set your own state in the PinterestOAuth class.

Thank you.

Nice!

No issue. I work on the developer API at Pinterest and came across your project. Just wanted to say thanks, your open-source work is awesome. You're the man!

Invalid grant response when call getauthorizetoken

you can fix this issue by replace getLoginUrl method to this in file
vendor\dirkgroenen\pinterest-api-php\src\Pinterest\Auth\PinterestOAuth.php

public function getLoginUrl( $redirect_uri, $scopes = array("read_public") )
    {
        $queryparams = array(
            "response_type"     => "code",
            "redirect_uri"      => $redirect_uri,
            "client_id"         => $this->client_id,
            "client_secret"     => $this->client_secret,
            "scope"             => implode(",", $scopes),
            "state"             => $this->state
        );

        // Build url and return it
        return sprintf( "%s?%s", self::AUTH_HOST, http_build_query($queryparams) );
    }

Pagination

Hi!

Great plugin! So thanks for that! I was just wondering if there is any documentation/notes on pagination calls in your package? I am probably missing something very obvious, I can access the 'next' field showing me the URL to post but unless I hack my own calls I was wondering if it was built in?

$boards = $pinterest->following->boards();
echo $boards->pagination['next'] // this prints pinterests next page URL

Cheers

Can i upload 5 image at once in a pin post ad?

Hello ,
I need to add to the pintrest api the option to add and upload Five(5) Images for each Pin Post Ad, right now the script allows to only Add One(1) Image per Pin Post Ad. is it possible? if yes , how can i do this? please help me.

curl_copy_handle() causes exceptions not being thrown

Hi,
In this file dirkgroenen\pinterest-api-php\src\Pinterest\Utils\CurlBuilder.php on line 198 you are creating second cUrl handle with curl_copy_handle() which means response code is not passed to $this->curl and therefore no exceptions are being thrown in dirkgroenen\pinterest-api-php\src\Pinterest\Transport\Request.php on line 209. Why do you need second cUrl handle anyway? Can't you use just $this->curl ? With just one curl handle it seems to work fine.
Thanks.

where is autoload.php?

Hi, I am getting an error about autoload.php. It is included in bootstrap.php as
require DIR . "/../../vendor/autoload.php";

but I don't find it anywhere.

Thanks for your help!

Error status 500

I have already configured the .env file with appID and Secret from Pinterest. After that I changed the url to my own, but finally I got this such error:

{"status": "500", "message": "Something failed on our end"}

my question is how can I know this error mean any why I got it?

here's my url : https://pinterest-samphors.c9users.io/demo/

Error Loader.php on line 75

I got this error when I typed "composer update" to get vendor folder and after that I started to do nothing, I tried to access to the file, and I saw this message :

Fatal error: Uncaught exception 'Dotenv\Exception\InvalidPathException' with message 'Unable to read the environment file at C:\xampp\htdocs\pinterst_fancybox\demo\.env.' in C:\xampp\htdocs\pinterst_fancybox\vendor\vlucas\phpdotenv\src\Loader.php:75 Stack trace: #0 C:\xampp\htdocs\pinterst_fancybox\vendor\vlucas\phpdotenv\src\Loader.php(52): Dotenv\Loader->ensureFileIsReadable() #1 C:\xampp\htdocs\pinterst_fancybox\vendor\vlucas\phpdotenv\src\Dotenv.php(50): Dotenv\Loader->load() #2 C:\xampp\htdocs\pinterst_fancybox\demo\boot.php(9): Dotenv\Dotenv->load() #3 C:\xampp\htdocs\pinterst_fancybox\demo\index.php(1): require('C:\\xampp\\htdocs...') #4 {main} thrown in C:\xampp\htdocs\pinterst_fancybox\vendor\vlucas\phpdotenv\src\Loader.php on line 75

How to get popular pin?

Hallo,
I found there is no documentation about getting popular pin or post.
Is there any chance to do that?

Thank you.

Having issues while creating Pins

Hey,

Hope you are doing good.

Thanks for adding autoload.php file. it's working Awesome now :)

I have issues with creating the pins now,

Error: Fatal error: Uncaught exception 'DirkGroenen\Pinterest\Exceptions\PinterestException' with message 'Pinterest error (code: 400) with message: Parameter 'board' is required.

Code:

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

I have already created Board with Name "testappspins" within My Pintrest Account.

Can you please help me?

Installation issue - package not found

Hi, I'm new to Composer so I don't know if this is me or an issue, but when I run

composer require dirkgroenen/Pinterest-API-PHP

I get

The requested package dirkgroenen/pinterest-api-php No version set (parsed as 1.0.0) could not be found

The error provides links to info about security settings, but from what I can see, at least 0.2.2 is a stable release. Again, apologies if this is an issue my end rather!

Getting auth token is not working

Hello. I've been following your Auth flow and have gotten stuck on a piece. I have pinterest redirecting back to my app with an access_token in the url. When I pass this access_token into the
$pinterest->auth->getOAuthToken($code) function, I get the following error.

An uncaught Exception was encountered

Type: DirkGroenen\Pinterest\Exceptions\PinterestException

Message: Pinterest error (code: 404) with message: 404: Not Found

Filename: /var/www/dev/vendor/dirkgroenen/pinterest-api-php/src/Pinterest/Transport/Request.php

Line Number: 193

Add pagination to Collection

Based on issue #60

Right now the user has to manually specify it's cursor in case he wants to paginate his requests. Adding a method to the collection which uses the next attribute would make it a lot easier to paginate a collection.

Class 'Dotenv\Dotenv' not found

I have not started yet with the code insider, after get the file downloaded via composer and put it my local server "xampp", I got this error :
Fatal error: Class 'Dotenv\Dotenv' not found in C:\xampp\htdocs\pinterst_fancybox\demo\boot.php on line 8

please how can i solve this , i can't retrieve user info

Warning: curl_setopt_array(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set in /var/www/vhosts/showmb.com/dev1/maged/DirkGroenen/Pinterest/Utils/CurlBuilder.php on line 70

Fatal error: Uncaught exception 'DirkGroenen\Pinterest\Exceptions\PinterestException' with message 'Pinterest error (code: 401) with message: Authorization failed.' in /var/www/vhosts/showmb.com/dev1/maged/DirkGroenen/Pinterest/Transport/Request.php:196 Stack trace: #0 /var/www/vhosts/showmb.com/dev1/maged/DirkGroenen/Pinterest/Transport/Request.php(78): DirkGroenen\Pinterest\Transport\Request->execute('GET', 'https://api.pin...') #1 /var/www/vhosts/showmb.com/dev1/maged/DirkGroenen/Pinterest/Endpoints/Users.php(28): DirkGroenen\Pinterest\Transport\Request->get('me', Array) #2 /var/www/vhosts/showmb.com/dev1/maged/init.php(41): DirkGroenen\Pinterest\Endpoints\Users->me(Array) #3 /var/www/vhosts/showmb.com/dev1/maged/index.php(16): include('/var/www/vhosts...') #4 {main} thrown in /var/www/vhosts/showmb.com/dev1/maged/DirkGroenen/Pinterest/Transport/Request.php on line 196

PinterestException Codes

It would be helpful if, when you raised a PinterestException, you set an error code, so our handlers could sort out what sort of error it was in order to handle it appropriately.

Was there an error in the request? If Pinterest responded with an error, what error was it? (perhaps in Request.php, replacing lines 190-193 with this:
// Check the response code
if ( $response->getResponseCode() >= 400 ) {
throw new PinterestException( 'Pinterest error (code: ' . $response->getResponseCode() . ') with message: ' . $response->message, $response->getResponseCode() );
}

Thanks!

$pinterest->following->boards() gives 401 - Anauthorized error

Here is my code
$pinterest = new Pinterest(self::PINTEREST_APP_ID, self::PINTEREST_APP_SECRET);
$pinterest->auth->setOAuthToken($pinterest_access_token);
(I have already got an access token, and as it is permanent credential, I save it in db and retreive every time I need it)
$pinterest->following->boards();
Fatal error: Uncaught exception 'DirkGroenen\Pinterest\Exceptions\PinterestException' with message 'Pinterest error (code: 401) with message: Authorization failed.' in C:\xampp\htdocs\9facts\wp-content\plugins\WJF\Pinterest-API-PHP-master\src\Pinterest\Transport\Request.php on line 238

DirkGroenen\Pinterest\Exceptions\PinterestException: Pinterest error (code: 401) with message: Authorization failed. in C:\xampp\htdocs\9facts\wp-content\plugins\WJF\Pinterest-API-PHP-master\src\Pinterest\Transport\Request.php on line 238

Although
$pinterest->users->getMeBoards(); works fine
Can anyone help

Composer is giving requirements could not be resolved error.

Hi Dirk, thank you very much for the wrapper. :)

I can't get it to work, though. When I install the package using composer by typing

C:\xampp\htdocs\pinterest>composer require dirkgroenen/Pinterest-API-PHP 0.2.11

I get the following error message:

Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested package dirkgroenen/pinterest-api-php No version set (parsed as 1.0.0) is satisfiable by dirkgroenen/pinterest-api-php[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability.

I have not made any changes to the composer.json file. Here is some of its code:

"require": { "php": ">=5.4", "ext-curl": "*" }, "require-dev": { "phpunit/phpunit": "4.7.*", "vlucas/phpdotenv": "^2.2" }, "autoload": { "psr-4": { "DirkGroenen\\Pinterest\\": "src/Pinterest" } }, "autoload-dev": { "psr-4": { "DirkGroenen\\Pinterest\\Tests\\": "tests/Pinterest" } }

Could you please help me resolve this issue?

Thanks.

/me/pins not returning full data from pinterest

Hello,

The pinterest->users->getMePins() and the pinterest->pins->get($pinId) aren't returning the full data from the pinterest API.
If I browse to the endpoint in browser, to the corresponding endpoint, I get more data back than the returned data in code.

Ie: in browser:

{
"attribution": null,
"creator": {
"url": "https://www.pinterest.com/nwidart/",
"first_name": "Nicolas",
"last_name": "Widart",
"id": "100979354053381714"
},
"url": "https://www.pinterest.com/pin/100979216618556872/",
"media": {
"type": "image"
},
"created_at": "2013-10-20T21:06:13",
"original_link": "http://www.corbiau.com/#houses",
"note": "Marc Corbiau | Uccle, Belgium, 2003",
"color": "#a9a6a4",
"link": "https://www.pinterest.com/r/pin/100979216618556872/4803529652880556599/6889b6ebba2030e5f0fd96acaaca324e402fc43ce2ba2e36f1738eba30c656bd",
"board": {
"url": "https://www.pinterest.com/nwidart/minimal-interiors-inspiration/",
"id": "100979285333932411",
"name": "Minimal interiors inspiration"
},
"counts": {
"likes": 0,
"comments": 0,
"repins": 0
},
"id": "100979216618556872",
"metadata": {}
},

Using the package:

"url" => "https://www.pinterest.com/pin/100979216618556872/"
    "note" => "Marc Corbiau | Uccle, Belgium, 2003"
    "link" => "https://www.pinterest.com/r/pin/100979216618556872/4803529652880556599/6889b6ebba2030e5f0fd96acaaca324e402fc43ce2ba2e36f1738eba30c656bd"
    "id" => "100979216618556872"

Did I miss something ?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.