-
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-1824 media sample methods, add uploads sample method call
- Loading branch information
1 parent
ae8d2d9
commit 769e562
Showing
2 changed files
with
117 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,67 @@ | ||
<?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 to make API requests for portal, client id, client secret with redirect uri | ||
$bynder = new BynderClient(new Oauth2\Configuration( | ||
$bynderDomain, | ||
$redirectUri, | ||
$clientId, | ||
$clientSecret, | ||
$token, | ||
['timeout' => 5] // Guzzle HTTP request options | ||
)); | ||
|
||
// if no access token, need to use OAuth flow to authorize and get access code, then use code to get token | ||
if ($token === null) { | ||
echo $bynder->getAuthorizationUrl([ | ||
'offline', | ||
'current.user:read', | ||
'current.profile:read', | ||
'asset:read', | ||
'asset:write', | ||
'meta.assetbank:read', | ||
'asset.usage:read', | ||
'asset.usage:write', | ||
]) . "\n\n"; | ||
|
||
$code = readline('Enter code: '); | ||
|
||
if ($code == null) { | ||
echo("Failed to get access token"); | ||
exit; | ||
} | ||
|
||
$token = $bynder->getAccessToken($code); | ||
} | ||
|
||
$assetBankManager = $bynder->getAssetBankManager(); | ||
|
||
// Upload a file and create an Asset. | ||
// Get Brands. Returns a Promise. | ||
$brandsListPromise = $assetBankManager->getBrands(); | ||
|
||
// Wait for the promise to be resolved. | ||
$brandsList = $brandsListPromise->wait(); | ||
|
||
// get brand to upload to | ||
if (!empty($brandsList)) { | ||
echo("Updating asset to brand id: " . $brandsList[0]['id']); | ||
$data = [ | ||
// Will need to create this file for successful test call | ||
'filePath' => 'image.png', | ||
'brandId' => $brandsList[0]['id'], | ||
'name' => 'Image name', | ||
'description' => 'Image description' | ||
]; | ||
$filePromise = $assetBankManager->uploadFileAsync($data); | ||
$fileInfo = $filePromise->wait(); | ||
var_dump($fileInfo); | ||
} | ||
} catch (Exception $e) { | ||
var_dump($e->getMessage()); | ||
} | ||
?> |