question

timst93 avatar image
0 Likes"
timst93 asked ·

OAuth token is not working

I'm trying to make a sandbox search call with the buy api. I created the App ID, Dev ID and Cert ID. I also have an ru name for sandbox and production. Then under "Get a Token from eBay via Your Application" page I speciefid an auth accept URL which is pointing to my applications php page. After log in to my sandbox user its redirecting me to my app url with some GET parameters. An "code" parameter and "expires_in" parameter (value: 299). I was expecting the code parameter is the token I need to use for the header when making calls, put I get the following error:

{ "errors" : [ { "errorId" : 1001, "domain" : "OAuth", "category" : "REQUEST", "message" : "Invalid access token", "longMessage" : "Invalid access token. Check the value of the Authorization HTTP request header." } ] }1

When I Generate an OAuth code at the ebay developer page under "Get a User Token Here" and use this one instead the request is working. The Generated code at the ebay page is also much longer compared to the one I get after Authentification as GET parameter.


My code:

$token_code = $_GET['code'];
$url = "https://api.sandbox.ebay.com/buy/browse/v1/item_summary/search?q=drone&limit=3";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    "Authorization: Bearer $token_code"
));
$response = curl_exec($curl);
echo $response;


What I'm doing wrong here and how to get a working token after OAuth?

Best regards

tokenPHPsearchoauthbuycode
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
vertika_developersupport avatar image
0 Likes"
vertika_developersupport answered ·

HI @timst93,

You are using Auth n Auth token hence getting "Invalid access token" error as this request requires oAuth token.
To get an oAuth Application access token via the UI please follow below steps:

1. Navigate to your OAuth credentials page on the eBay Developers Program website.
2. Next to the App ID listing of the environment you want to generate a token for, click the User Tokens link.
3. On the resulting page, click the Get OAuth Application Token link
You can use this Application token to make requests to the APIs in the environment for which the token was generated. You can even copy the returned access token for use in the API Explorer.
For more reference please visit here:
https://developer.ebay.com/api-docs/static/oauth-ui-tokens.html#app

Best Regards,
eBay Developer Support

· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.