【问题标题】:How to make a request with PHPLeague oAuth2 client?如何使用 PHP League oAuth2 客户端发出请求?
【发布时间】: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 变量的正确方法是什么?

提前致谢。

【问题讨论】:

    标签: php api oauth-2.0


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-08-19
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 2015-04-26
      • 2013-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多