如何解决([错误] => invalid_client [错误说明] =>客户端身份验证失败)

时间:2020-01-01 07:03:11

标签: php codeigniter ebay-api ebay-sdk

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);}

2 个答案:

答案 0 :(得分:1)

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

如果您尝试获取初始的“ AccessToken” (又名UserAccessToken,access_token,AuthToken等),那么您应该包括{{1 }}参数。因此,您的请求正文应如下所示:

scope

grant_type=authorization_code&redirect_uri=<redirect_uri>&code=<authorization_code> here返回的值。

有关差异的概述,我建议在主题的this answer上推荐official docs

答案 1 :(得分:0)

尝试此代码

  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);
}