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);}
看起来你对authorization_token
感到refresh_token
混淆,因为你在两个不同的请求之间混合了不兼容的参数。
如果您尝试获取初始"AccessToken"(又名UserAccessToken、access_token、AuthToken 等(,则不应在请求正文中包含scope
参数。 因此,请求正文应如下所示:
grant_type=authorization_code&redirect_uri=<redirect_uri>&code=<authorization_code>
其中<authorization_code>
是从此处返回的值。
对于差异的概述,我推荐这个答案而不是关于该主题的官方文档。
试试这段代码
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);
}