PHP code example of lemaur / laravel-pinterest-api
1. Go to this page and download the library: Download lemaur/laravel-pinterest-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lemaur / laravel-pinterest-api example snippets
// 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(),
* ]);
*/
}
// 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,
],
];
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...
));
}
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),
));
}