【问题标题】:how to resolve ( [error] => invalid_client [error_description] => client authentication failed ) for ebay如何为 ebay 解决([error] => invalid_client [error_description] => client authentication failed)
【发布时间】:2020-04-20 08:47:07
【问题描述】:
public function authorizationToken(){
$link = "https://api.ebay.com/identity/v1/oauth2/token";
$codeAuth = base64_encode($this->clientID.':'.$this->certID);
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded','Authorization: Basic '.$codeAuth));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=authorization_code&code=".urlencode($this->authCode)."&redirect_uri=".$this->ruName."&scope=".urlencode('https://api.ebay.com/oauth/api_scope'));
$response = curl_exec($ch);
$json = json_decode($response, true);$info = curl_getinfo($ch);
curl_close($ch);print_r($json);}

【问题讨论】:

标签: php codeigniter ebay-api ebay-sdk


【解决方案1】:

您似乎将 refresh_tokenauthorization_token 混淆了,因为您在两个不同的请求之间混合了不兼容的参数。

如果您尝试获取初始的“AccessToken”(AKA UserAccessToken、access_token、AuthToken,...),那么您应该包含scope请求正文中的参数。所以你的请求正文应该是这样的:

grant_type=authorization_code&redirect_uri=<redirect_uri>&code=<authorization_code>

其中&lt;authorization_code&gt; 是从here 返回的值。

对于差异的概述,我建议this answer 而不是official docs

【讨论】:

    【解决方案2】:

    试试这个代码

      public function authorizationToken(){
        $link = "https://api.ebay.com/identity/v1/oauth2/token";
        $codeAuth = base64_encode($this->clientID.':'.$this->certID);
        $ch = curl_init($link);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded','Authorization: Basic '.$codeAuth));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials&scope=".urlencode('https://api.ebay.com/oauth/api_scope'));
        $response = curl_exec($ch);
        $json = json_decode($response, true);
        $info = curl_getinfo($ch);
        curl_close($ch);
        print_r($json);
    }
    

    【讨论】:

    • 您是否传递了正确的客户端 ID 和客户端密码?检查此链接developer.ebay.com/api-docs/static/…
    • 是的,但是 $this->authCode = base64_encode($this->clientID.':'.$this->certID);我已经通过了这样的 atuhcode
    • echo 2 varibales $this->clientID 和 $this->certID 并检查您是否正确
    • $this->devID = 'XXXX'; $this->appID = 'XXXX'; $this->certID = 'XXXX'; $this->clientID = 'XXXX'; $this->serverUrl = 'api.ebay.com/ws/api.dll'; $this->authCode = base64_encode($this->clientID.':'.$this->certID); $this->authToken=""; $this->refreshToken=""; $this->ruName="XXXX";
    • 使用 echo 检查了 cliendid 和 certid。两者都是正确的
    猜你喜欢
    • 2017-01-11
    • 1970-01-01
    • 2018-05-22
    • 2022-10-23
    • 1970-01-01
    • 1970-01-01
    • 2022-12-29
    • 2017-06-19
    • 2014-11-28
    相关资源
    最近更新 更多