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.

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

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.

timst93 avatar image
0 Likes"
timst93 answered

Hello and thanks for your answer.

The generated OAuth token from the UI is working, but its expering after 2 hourse already and it would be impratical for the employees who have to use the script later to always regenrate the token from the UI.


What I'm using is OAuth. I was using the following url from Developer program page mentioned under "Your branded eBay Sandbox Sign In (OAuth)":


https://auth.sandbox.ebay.com/oauth2/authorize?client_id=OUR_CLIENT_ID&response_type=code&redirect_uri=OUR_REDIRECT_URI&scope=https://api.ebay.com/oauth/api_scope https://api.ebay.com/oauth/api_scope/buy.order.readonly https://api.ebay.com/oauth/api_scope/buy.guest.order https://api.ebay.com/oauth/api_scope/sell.marketing.readonly https://api.ebay.com/oauth/api_scope/sell.marketing https://api.ebay.com/oauth/api_scope/sell.inventory.readonly https://api.ebay.com/oauth/api_scope/sell.inventory https://api.ebay.com/oauth/api_scope/sell.account.readonly https://api.ebay.com/oauth/api_scope/sell.account https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly https://api.ebay.com/oauth/api_scope/sell.fulfillment https://api.ebay.com/oauth/api_scope/sell.analytics.readonly https://api.ebay.com/oauth/api_scope/sell.marketplace.insights.readonly https://api.ebay.com/oauth/api_scope/commerce.catalog.readonly https://api.ebay.com/oauth/api_scope/buy.shopping.cart https://api.ebay.com/oauth/api_scope/buy.offer.auction https://api.ebay.com/oauth/api_scope/commerce.identity.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.email.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.phone.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.address.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.name.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.status.readonly https://api.ebay.com/oauth/api_scope/sell.finances https://api.ebay.com/oauth/api_scope/sell.item.draft https://api.ebay.com/oauth/api_scope/sell.payment.dispute https://api.ebay.com/oauth/api_scope/sell.item 

Also the URL in the addressbar while authorisation process is indicating it's OAuth:

https://auth.sandbox.ebay.com/oauth2/consents?client_id=...

But the code I get is not working. I always get the massage that the token is invalid. The token I get is also much shorter then the UI generated one.


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.