Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHPLeague oAuth2客户端发出请求?_Php_Api_Oauth 2.0 - Fatal编程技术网

如何使用PHPLeague oAuth2客户端发出请求?

如何使用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

我正在为一个提供oAuth2 API的客户集成一个附属平台,通常不使用oAuth2做大量工作

我已经决定为我的客户使用PHP Leagues oAuth2包:

不管怎样,我有一个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变量的正确方法是什么


提前感谢。

意识到我可以简单地将get vars包含在URI alla中:

$productSearchApiBaseUri = 'https://api.rakutenmarketing.com/productsearch/1.0?keyword=shirt';