如何使用PHPLeague oAuth2客户端发出请求?
我正在为一个提供oAuth2 API的客户集成一个附属平台,通常不使用oAuth2做大量工作 我已经决定为我的客户使用PHP Leagues oAuth2包: 不管怎样,我有一个accessToken没问题!使用以下命令:如何使用PHPLeague oAuth2客户端发出请求?,php,api,oauth-2.0,Php,Api,Oauth 2.0,我正在为一个提供oAuth2 API的客户集成一个附属平台,通常不使用oAuth2做大量工作 我已经决定为我的客户使用PHP Leagues oAuth2包: 不管怎样,我有一个accessToken没问题!使用以下命令: $provider = new GenericProvider([ 'clientId' => $this->config->affiliates->rakuten->clientId, 'clientSec
$provider = new GenericProvider([
'clientId' => $this->config->affiliates->rakuten->clientId,
'clientSecret' => $this->config->affiliates->rakuten->clientSecret,
'redirectUri' => 'http://www.newintoday.com/',
'urlAuthorize' => 'https://api.rakutenmarketing.com/token', // Ignore
'urlAccessToken' => 'https://api.rakutenmarketing.com/token',
'urlResourceOwnerDetails' => 'https://api.rakutenmarketing.com/' // Ignore
]);
try {
// Try to get an access token using the resource owner password credentials grant.
$accessToken = $provider->getAccessToken('password', [
'username' => $this->config->affiliates->rakuten->username,
'password' => $this->config->affiliates->rakuten->password,
'scope' => $this->config->affiliates->rakuten->publisherId,
]);
$productSearchApiBaseUri = 'https://api.rakutenmarketing.com/productsearch/1.0';
$request = $provider->getAuthenticatedRequest('GET', $productSearchApiBaseUri, $accessToken, [
'body' => '?keyword=shirt',
]);
\Utils::dump($provider->getResponse($request));
} catch (IdentityProviderException $e) {
echo $e->getMessage();
}
我的问题是,一旦我们有了accessToken,我们在其中使用什么来发出请求,我就按照代码进行操作,得出了上面的结果,但是API回答说没有指定关键字?是
$request = $provider->getAuthenticatedRequest('GET', $productSearchApiBaseUri, $accessToken, [
'body' => 'keyword=shirt',
]);
为其提供GET变量的正确方法是什么
提前感谢。意识到我可以简单地将get vars包含在URI alla中:
$productSearchApiBaseUri = 'https://api.rakutenmarketing.com/productsearch/1.0?keyword=shirt';