-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API-2195 Add client credentials auth support for PHP SDK (#75)
* API-2195 add methods for client credentials, sample for oauth client credentials * API-2195 update README
- Loading branch information
1 parent
6cc261a
commit c31b985
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
require_once(__DIR__ . '/../vendor/autoload.php'); | ||
require_once(__DIR__ . '/sample_config.php'); | ||
use Bynder\Api\BynderClient; | ||
use Bynder\Api\Impl\OAuth2; | ||
|
||
|
||
try { | ||
// instantiate BynderClient, redirectUri and token are null (client credentials) | ||
$bynder = new BynderClient(new Oauth2\Configuration( | ||
$bynderDomain, | ||
null, | ||
$clientId, | ||
$clientSecret, | ||
null, | ||
['timeout' => 5] // Guzzle HTTP request options | ||
)); | ||
|
||
// use client credentials grant type to get access token | ||
if ($token === null) { | ||
$token = $bynder->getAccessTokenClientCredentials(); | ||
} | ||
|
||
$assetBankManager = $bynder->getAssetBankManager(); | ||
|
||
// Get Brands. Returns a Promise. | ||
$brandsListPromise = $assetBankManager->getBrands(); | ||
// Wait for the promise to be resolved. | ||
$brandsList = $brandsListPromise->wait(); | ||
|
||
if (!empty($brandsList)) { | ||
foreach ($brandsList as $brand) { | ||
echo("Brand ID: " . $brand['id'] . "\n"); | ||
var_dump($brand); | ||
} | ||
} | ||
|
||
// get derivatives | ||
$derivativesPromise = $assetBankManager->getDerivatives(); | ||
$derivativesList = $derivativesPromise->wait(); | ||
|
||
if (!empty($derivativesList)) { | ||
echo("Derivatives: " . "\n"); | ||
var_dump($derivativesList); | ||
} | ||
|
||
// Get Media Items list. | ||
// Optional filter. | ||
$query = [ | ||
'count' => true, | ||
'limit' => 10 | ||
]; | ||
|
||
$mediaListPromise = $assetBankManager->getMediaList($query); | ||
$mediaList = $mediaListPromise->wait(); | ||
|
||
// outputs list of media items, print media item | ||
if (!empty($mediaList) && !empty($mediaList['media'])) { | ||
foreach ($mediaList['media'] as $media) { | ||
echo("Media ID: " . $media['id'] . "\n"); | ||
var_dump($media); | ||
} | ||
} | ||
} catch (Exception $e) { | ||
var_dump($e); | ||
} | ||
|
||
?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters