dmf-软件/oauth2-trustpilot

PHP League OAuth2-Client 的 Trustpilot 客户端提供者

v1.0.1 2022-04-12 19:53 UTC

This package is auto-updated.

Last update: 2024-09-13 11:31:14 UTC


README

安装

composer require dmt-software/oauth2-trustpilot

用法

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
    }
}

更多示例请见 league/oauth2-client

错误处理

遗憾的是,在出现错误的情况下,响应体并不一致。为了更好地理解请求失败的原因,请调用 IdentityProviderException::getResponseBody 方法。