PHP code example of dmt-software / oauth2-trustpilot
1. Go to this page and download the library: Download dmt-software/oauth2-trustpilot 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/ */
dmt-software / oauth2-trustpilot example snippets
use DMT\OAuth2\Client\Provider\Trustpilot;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
$provider = new Trustpilot([
'clientId' => '{ your_client_id }',
'clientSecret' => '{ your_client_secret }',
]);
try {
$accessToken = $provider->getAccessToken(
'password', [
'username' => '{ your_username }',
'password' => '{ your_password }'
]
);
} catch (IdentityProviderException $exception) {
if ($exception->getCode() === 401) {
// token is expired
}
if ($exception->getCode() === 429) {
// too many requests
}
}