Download the PHP package aislandener/pinterest-laravel without Composer
On this page you can find all versions of the php package aislandener/pinterest-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aislandener/pinterest-laravel
More information about aislandener/pinterest-laravel
Files in aislandener/pinterest-laravel
Package pinterest-laravel
Short Description Laravel Package for the official Pinterest API
License Apache-2.0
Informations about the package pinterest-laravel
Pinterest API - Laravel
A Package for using official Pinterest API with Laravel.
Requirements
- PHP 5.4 or higher
- Laravel 5.0 or Above
- 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
andclient_secret
are in this caseapp_id
andapp_secret
.
Installation
The Pinterest API wrapper is available on Composer.
Configuration
Add service provider for $providers[]
array in config/app.php
array.
Run vendor:publish
command to copy pinterest configuration to app configs directory.
Update .env
file and fill in these env
variables.
Getting access token in exchange for code
After you have initialized the class you can get a login URL:
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:
Get the user's profile
To get the profile of the current logged in user you can use the Users::me(<array>);
method.
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
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:
Response:
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):
The response will now be:
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()
Returns: array<Model>
Get item at index
get( int $index )
Returns: Model
Check if collection has next page
hasNextPage()
Returns: Boolean
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");
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 );
Set access_token
setOAuthToken( string $access_token );
Get state
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.
Rate limit
Get limit
getRateLimit();
This method can be used to get the maximum number of requests.
Returns: int
Get remaining
getRateLimitRemaining();
This method can be used to get the remaining number of calls.
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 );
Returns: User
Find a user
find( string $username_or_id );
Returns: User
Get user's pins
getMePins( array $data );
Returns: Collection<Pin>
Search in user's pins
getMePins( string $query, array $data );
Returns: Collection<Pin>
Search in user's boards
searchMeBoards( string $query, array $data );
Returns: Collection<Board>
Get user's boards
getMeBoards( array $data );
Returns: Collection<Board>
Get user's followers
getMeFollowers( array $data );
Returns: Collection<Pin>
Boards
The methods below are available through Pinterest::boards
.
Get board
get( string $board_id, array $data );
Returns: Board
Create board
create( array $data );
Returns: Board
Edit board
edit( string $board_id, array $data, string $fields = null );
Returns: Board
Delete board
delete( string $board_id, array $data );
Returns: True|PinterestException
Pins
The methods below are available through Pinterest::pins
.
Get pin
get( string $pin_id, array $data );
Returns: Pin
Get pins from board
fromBoard( string $board_id, array $data );
Returns: Collection<Pin>
Create pin
create( array $data );
Creating a pin with an image hosted somewhere else:
Creating a pin with an image located on the server:
Creating a pin with a base64 encoded image:
Returns: Pin
Edit pin
edit( string $pin_id, array $data, string $fields = null );
Returns: Pin
Delete pin
delete( string $pin_id, array $data );
Returns: True|PinterestException
Following
The methods below are available through Pinterest::following
.
Following users
users( array $data );
Returns: Collection<User>
Following boards
boards( array $data );
Returns: Collection<Board>
Following interests/categories
interests( array $data );
Returns: Collection<Interest>
Follow an user
followUser( string $username_or_id );
Returns: True|PinterestException
Unfollow an user
unfollowUser( string $username_or_id );
Returns: True|PinterestException
Follow a board
followBoard( string $board_id );
Returns: True|PinterestException
Unfollow a board
unfollowBoard( string $board_id );
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 );
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 );
Returns: True|PinterestException
All versions of pinterest-laravel with dependencies
ext-curl Version *