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);}
Asked
Active
Viewed 5,998 times
2

Lord Elrond
- 13,430
- 7
- 40
- 80

phpfan
- 29
- 1
- 8
-
please help me out – phpfan Jan 01 '20 at 07:03
-
check this link https://www.angelleye.com/how-to-integrate-ebay-apis-with-php-part-1/ – Jinesh Jan 01 '20 at 07:24
2 Answers
1
It looks like you are getting refresh_token
confused with authorization_token
, because you are mixing incompatible parameters between the two different requests.
If you are trying to get the initial "AccessToken" (AKA UserAccessToken, access_token, AuthToken, ...), then you should not include the scope
parameter in your request body. So your request body should look like this:
grant_type=authorization_code&redirect_uri=<redirect_uri>&code=<authorization_code>
Where <authorization_code>
is the value that is returned from here.
For an overview of the difference, I'd recommend this answer over the official docs on the topic.

Lord Elrond
- 13,430
- 7
- 40
- 80
0
Try this 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);
}

Jinesh
- 1,554
- 10
- 15
-
1have you pass proper client id and client secret? Check this link https://developer.ebay.com/api-docs/static/oauth-base64-credentials.html – Jinesh Jan 01 '20 at 07:39
-
yes, but $this->authCode = base64_encode($this->clientID.':'.$this->certID); i have passed atuhcode like this – phpfan Jan 01 '20 at 07:44
-
echo 2 varibales $this->clientID and $this->certID and check you have proper or not – Jinesh Jan 01 '20 at 07:45
-
$this->devID = 'XXXX'; $this->appID = 'XXXX'; $this->certID = 'XXXX'; $this->clientID = 'XXXX'; $this->serverUrl = 'https://api.ebay.com/ws/api.dll'; $this->authCode = base64_encode($this->clientID.':'.$this->certID); $this->authToken =""; $this->refreshToken =""; $this->ruName= "XXXX"; – phpfan Jan 01 '20 at 07:46
-
-
I have updated my answer please check it if it solve your problem please accept it. – Jinesh Jan 01 '20 at 07:56
-
-
-
have you put proper authorization code in urlencode($this->authCode)? Have you create user token? – Jinesh Jan 01 '20 at 08:49