lemaur/laravel-pinterest-api
最新稳定版本:0.3.5
Composer 安装命令:
composer require lemaur/laravel-pinterest-api
包简介
关键字:
README 文档
README
An Object-Oriented wrapper for consuming Pinterest API with Laravel.
It uses Pinterest API v5.
Warning: This package DOESN'T store Pinterest's credentials, you should provide your own logic!
👉 Please read carefully the Manage credentials section! 👈
Support Me
Hey folks,
Do you like this package? Do you find it useful, and it fits well in your project?
I am glad to help you, and I would be so grateful if you considered supporting my work.
You can even choose 😃:
- You can sponsor me 😎 with a monthly subscription.
- You can buy me a coffee ☕ or a pizza 🍕 just for this package.
- You can plant trees 🌴. By using this link we will both receive 30 trees for free and the planet (and me) will thank you.
- You can "Star ⭐" this repository (it's free 😉).
Roadmap
This package still in development.
You can vote for endpoints not yet covered by requesting them here.
If so, it would be great if you wanted sponsor me to support my work.
- Pins
- list
- create
- get
- delete
- update
- save
- analytics
- Boards
- list
- create
- get
- delete
- update
- pins
- Board Sections
- Ad Accounts
- Ad Groups
- Ads
- Audience Insights
- Audiences
- Bulk
- Campaigns
- Catalogs
- Conversion Events
- Conversion Tags
- Customer Lists
- Integrations
- Interests
- Keywords
- Media
- OAuth
- Order Lines
- Product Group Promotions
- Product Groups
- Resources
- Search
- Terms
- Terms of Service
- User Account
Installation
You can require the package via composer:
composer require lemaur/laravel-pinterest-api
You can install it with:
php artisan pinterest-api:install
Manage credentials
Pinterest API Authentication follows the OAuth2 standard.
The package contains helpful methods to obtain the credentials from Pinterest OAuth server, but where to store them is up to you! Every project is different, with different requirements. You can store credentials on disk, or you can write them on DB and so on...
Note: You'll need to register a new app on Pinterest and get the app ID and secret key.
But don't worry, we'll do it in the next section.
Here I'll show you how to configure your project to manage credentials.
The authentication flow returns an object containing access_token and refresh_token within the expiration timestamps and other information.
Here an example:
{
"access_token": "{an access token string prefixed with 'pina'}",
"refresh_token": "{a refresh token string prefixed with 'pinr'}",
"response_type": "authorization_code",
"token_type": "bearer",
"expires_in": 2592000,
"refresh_token_expires_in": 31536000,
"scope": "boards:read boards:write pins:read"
}
The package emits Lemaur\Pinterest\Events\CredentialsRetrieved::class event within Lemaur\Pinterest\Data\OAuthData object when it receives the credentials.
You can listen for this event in your project and store the credentials where you want.
To do that, you need to create a new listener
php artisan make:listener --event=\\Lemaur\\Pinterest\\Events\\CredentialsRetrieved StorePinterestCredentials
And inside the handle method you can decide where to store the credentials.
// file: app/Listeners/StorePinterestCredentials.php /** * Handle the event. * * @param \Lemaur\Pinterest\Events\CredentialsRetrieved $event * @return void */ public function handle(CredentialsRetrieved $event) { // Store the credentials from `$event->oauth`. // Where `$event->oauth` is an instance of `Lemaur\Pinterest\Data\OAuthData`. /** * For e.g. you can extend your User model by adding a json column `pinterest_credentials` * and store the credentials for each authenticated user. * * \Illuminate\Support\Facades\Auth::user()->update([ * 'pinterest_credentials' = $event->oauth->toArray(), * ]); */ }
Don't forget to register the listener in the App\Providers\EventServiceProvider.
// file: app/Providers/EventServiceProvider.php /** * The event listener mappings for the application. * * @var array<class-string, array<int, class-string>> */ protected $listen = [ \Lemaur\Pinterest\Events\CredentialsRetrieved::class => [ \App\Listeners\StorePinterestCredentials::class, ], ];
Now it's time to edit the service provider.
Open App\Providers\PinterestServiceProvider, and inside the register method you will find a predefined implementation.
As you can see in the @TODO comment, here is where you should pass the credentials you previously stored.
public function register(): void { $this->app->singleton(PinterestContract::class, fn (Application $app) => new PinterestService( config: ConfigData::fromConfig($app['config']['pinterest']), oauth: OAuthData::from([]), // @TODO: <-- please fill in the credentials... )); }
In the previous examples we stored the credentials in the user's table.
So here, we can fetch them from the authenticated user.
public function register(): void { $this->app->singleton(PinterestContract::class, fn (Application $app) => new PinterestService( config: ConfigData::fromConfig($app['config']['pinterest']), oauth: OAuthData::from(\Illuminate\Support\Facades\Auth::user()->pinterest_credentials), )); }
Require Pinterest Access
Register and get your app ID and secret key
Note: internally
app IDisclient_id, internallysecret keyisclient_secret!
- Log into www.pinterest.com; open a new tab with the account that you’ll use to manage your apps.
- Go to My Apps.
- Select Connect app and complete the request form with your app information.
- Submit your request to get trial access.
- As soon as Pinterest completes the review, Pinterest will notify you by email.
- Once you have received the email approval, go to My Apps to see your app ID and secret key.
It's now time to copy/paste the app ID and secret key to the .env file.
PINTEREST_API_CLIENT_ID="app ID" PINTEREST_API_CLIENT_SECRET="secret key"
Configure the redirect URI
The package provides a default redirect URI /pinterest/callack. You are free to change it in your configuration file.
- Back to your Pinterest account.
- Go to My Apps and select your app.
- Go to Configure and, in Redirect URIs, enter the desired URI and save.
Note: For local development it's preferred to use
http://localhost/pinterest/callback
PINTEREST_API_REDIRECT_URI=http://localhost/pinterest/callback
Generate an access token
- To start the OAuth flow and request user access run
php artisan pinterest:get-access-code-link - Copy/Paste the link to your browser and follow the instructions on screen.
- At the end of the process you will see a white page with a text saying "All good! You can close this page."
Now you are ready to call the Pinterest API.
NOTES
Pinterest provides an access_token valid for 30 days and a refresh_token valid for 1 year.
The package automatically retrieves a new access token every time it expires, as long as the refresh token is still valid.
After 1 year, when you try to call an API endpoint, the package will throw a OAuthException with a message informing you to request a new access code.
If you are curious you can read the codebase to learn more.
Or you can use Lemaur\Pinterest\Facades\Pinterest::oauth()->credentials()->accessTokenExpiresIn to get the number of days before the access token will expire.
The same for the refresh token Lemaur\Pinterest\Facades\Pinterest::oauth()->credentials()->refreshTokenExpiresIn.
Testing
The package offers a nifty fake method to help you write your tests.
If you want some examples, I suggest to look at the package test suite.
Pinterst::assertSent(callable $callback): void
Pinterst::assertNotSent(callable $callback): void
Pinterst::assertSentCount(int $count): void
Pinterst::assertNothingSent(): void
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
lemaur/laravel-pinterest-api 适用场景与选型建议
lemaur/laravel-pinterest-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 486 次下载、GitHub Stars 达 5, 最近一次更新时间为 2023 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「laravel」 「pinterest」 「v5」 「lemaur」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lemaur/laravel-pinterest-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lemaur/laravel-pinterest-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lemaur/laravel-pinterest-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library to validate and parse social media profile URLs
This Plugin enables you to display RSS.App feeds (Instagram, Twitter, Facebook and more) in TYPO3 - more information on https://rss.app
A PSR-7 compatible library for making CRUD API endpoints
Laravel social media auto post package - Complete solution for posting to 8 major social media platforms
Pinterest extension for using via yii2-authclient
PHP Social Counter Plugin grabs the latest counts of your Fans/Followers etc. from your Favorite Social Networks and then displays them on your Blog. It is the perfect solution to encourage more users to join your network
统计信息
- 总下载量: 486
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-26