【发布时间】:2015-11-23 20:45:17
【问题描述】:
我正在与一个提供 oAuth2 API 的客户的附属平台集成,通常不会使用 oAuth2 进行大量工作。
我决定为我的客户,我将使用 PHP Leagues oAuth2 包:https://github.com/thephpleague/oauth2-client
反正我有accessToken没问题!使用以下内容:
$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 变量的正确方法是什么?
提前致谢。
【问题讨论】: