PHP code example of iammordaty / beatport-oauth-middleware

1. Go to this page and download the library: Download iammordaty/beatport-oauth-middleware 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/ */

    

iammordaty / beatport-oauth-middleware example snippets


use BeatportOauth\AccessTokenProvider;
use BeatportOauth\OauthMiddlewareFactory;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;

$oauthParams = [
   'consumer_key' => $_ENV['consumer_key'],
   'consumer_secret' => $_ENV['consumer_secret'],
   'username' => $_ENV['username'],
   'password' => $_ENV['password'],
];

$middleware = OauthMiddlewareFactory::create($oauthParams); 

$stack = HandlerStack::create();
$stack->push($middleware);

$client = new Client([
    'auth' => 'oauth',
    'base_uri' => AccessTokenProvider::BASE_URI,
    'handler' => $stack,
]);

$response = $client->get('catalog/3/tracks', [
    'query' => [ 'id' => 12387959 ],
]);

$contents = json_decode($response->getBody()->getContents(), true);

use BeatportOauth\OauthMiddlewareFactory;
use Cache\Adapter\PHPArray\ArrayCachePool;
use GuzzleHttp\HandlerStack;

$oauthParams = [/* */];
$cache = new ArrayCachePool(); // or any other PSR-16 compatible cache pool
$cacheConfig = [ 'key' => 'my-access-token-info' ]; // optional

$middleware = OauthMiddlewareFactory::createWithCachedToken(
    $oauthParams,
    $cache,
    $cacheConfig
);

$stack = HandlerStack::create();
$stack->push($middleware);