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

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

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

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

eisenbahnkartei avatar image
0 Likes"
eisenbahnkartei answered

Hallo Developer eBay,

please go on Account ebay.eisenbahnkartei@eisenbahnkartei.de

I'm go Torken.

Thanks
Do your send E-mail an ebay.eisenbahnkartei@eisenbahnkartei.de

· 1
10 |600

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

Alter Schwede, kam da vielleicht jemand strunz besoffen vom Karneval oder was möchte der Autor uns hier sagen? ;-))) LOL
0 Likes 0 ·
eisenbahnkartei avatar image
0 Likes"
eisenbahnkartei answered

Der Account ist noch nicht freigegeben. Bitte Developer eBay schalten Sie bitte frei.

10 |600

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

eisenbahnkartei avatar image
0 Likes"
eisenbahnkartei answered

Hello Developer eBay.com I'm Register,and to E -mail verrifzi zu subfullii.

So you can to pleased Go to Account ebay.eisenbahnkartei@eisenbahnkartei.de

So you sende E-Mail,and I'm send Account Name.

Thanks

Holger Schmitz

Eisenbahnkartei











· 1
10 |600

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

Mensch Holger, benutz doch wenigstens Google translate, die denken doch sonst alle wir deutschen haben nen vollschaden :-)))
0 Likes 0 ·
eisenbahnkartei avatar image
0 Likes"
eisenbahnkartei answered

@

michab2

003

Du brauchst uns.

Wir können Torken.

Tel 0049(0)2271993813

Sende eine

E -mail an Holger-schmitz@bilduploadfilter-Erfinder.de





10 |600

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

vihinte43 avatar image
0 Likes"
vihinte43 answered

@timst93 Have you solved this? I believe we have the same issue, especially since you said "The token I get is also much shorter then the UI generated one." I am doing something similar where I have code that takes the parameter and tries to use it however it seems that the code is not encoded and breaks my code. I cannot figure out a way to have Ebay encode this value before hitting my endpoint.

10 |600

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

joffs-e-experts avatar image
0 Likes"
joffs-e-experts answered

Hello timst93,

the code you got, which expires in 299 seconds, is just the first half of getting the final access token.

After getting the short code you need to make another request. Have a look here (7.): https://stackoverflow.com/questions/44603838/ebay-oauth-token-and-refresh-tokens

Following the guide there, you get your final access token data and a way to refresh the access token as it is just valid for 2 hours. The refresh token is good for 18 month and in 8. from the post you get an idea to renew the access token without having the hassle to "sign in and grant" again and again.

Good luck.

10 |600

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

alfredo.e-20 avatar image
0 Likes"
alfredo.e-20 answered

Follow the steps I hope it might be helpful to you :

Navigate to your OAuth credentials page on the eBay Developers Program website.
Next to the App ID listing of the environment you want to generate a token for, click the User Tokens link. mymilestonecard
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.

10 |600

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.