PHP Client for the Trustpilot API
This application is still in development and could implement breaking changes. Please use at your own risk.
You can install the package with composer
composer require justijndepover/trustpilot-api
To use the plugin in Laravel applications, please refer to the Laravel usage page
Connecting to Trustpilot:
$trustpilot = new Trustpilot(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
// open the trustpilot login
header("Location: {$trustpilot->redirectForAuthorizationUrl()}");
exit;
After connecting, Trustpilot will send a request back to your redirect uri.
$trustpilot = new Trustpilot(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
if ($_GET['error']) {
// your application should handle this error
}
$trustpilot->setAuthorizationCode($_GET['code']);
$trustpilot->connect();
// store these values:
$accessToken = $trustpilot->getAccessToken();
$refreshToken = $trustpilot->getRefreshToken();
$expiresAt = $trustpilot->getTokenExpiresAt();
Your application is now connected. To start fetching data:
$trustpilot = new Trustpilot(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
$trustpilot->setAccessToken($accessToken);
$trustpilot->setRefreshToken($refreshToken);
$trustpilot->setTokenExpiresAt($expiresAt);
// fetch data:
$trustpilot->get($url);
// you should always store your tokens at the end of a call
$accessToken = $trustpilot->getAccessToken();
$refreshToken = $trustpilot->getRefreshToken();
$expiresAt = $trustpilot->getTokenExpiresAt();
If you find any security related issues, please open an issue or contact me directly at [email protected].
If you wish to make any changes or improvements to the package, feel free to make a pull request.
The MIT License (MIT). Please see License File for more information.