question

lezzgiles avatar image
0 Likes"
lezzgiles asked

Need simple API example

I wrote a python script several years ago that uses the selling API to get listings - this info is then used to match up inventory against the Ebay listings, to make sure we don't have more of any item listed than is in the inventory, etc. This used a developer id, application id, and certificate id. I needed to regenerate the certificate id every few years, but this has been working well for about ten years.

Now I need to update to use oauth2. When I generate a user token it gives me one, but the expiration date is just two hours from now. Is there any way I can get tokens so my script works the way it did before, or will we need to log in to Ebay every two hours to get a new token?

oauth2
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.

lezzgiles avatar image
0 Likes"
lezzgiles answered

So it looks like the token it gives me works exactly the same way as the old auth'n'auth token, except it expires after two hours - so I have a workaround: just get a new token every couple of hours or when I need to use the script. However after doing some more reading, it looks like there should be a refresh token that my script can use to get a new valid token - but when I generate the user token, it only gives me the user token and not the refresh token. When I generate the token this way, is there an associated refresh token and if so how do I find it?

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.

alvisinwales avatar image
0 Likes"
alvisinwales answered

When you get your original user access token the response will also contain a refresh token.


When you need a new user access token you use the refresh token to get one. You don't need to get user consent every two hours.


The refresh token lasts for 18 months after which time you need to get user consent again.


https://developer.ebay.com/api-docs/static/oauth-authorization-code-grant.html#Getting2


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.

sagar_developersupport avatar image
0 Likes"
sagar_developersupport answered

Hi @lezzgiles,

For security, a User access token is short-lived. However, a Refresh token is long-lived and you can use it to renew a User access token after the token expires. The benefit is that you don't need to get the account-owner's consent each time you need to renew their User access token.

Ref:- https://developer.ebay.com/api-docs/static/oauth-refresh-token-request.html

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.

osask92 avatar image
0 Likes"
osask92 answered

When you get your original user access token the response will also contain a refresh token.

When you need a new user access token you use the refresh token to get one. You don't need to get user consent every two hours.

The refresh token lasts for 18 months after which time you need to get user consent again.

https://developer.ebay.com/api-docs/static/oauth-authorization-code-grant.html#Getting2/greatpeople

Very informative and useful article for beginners!



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.

eg960-67 avatar image
0 Likes"
eg960-67 answered

I believe you created good quality items in functions also. Keep working, congrats!


firstcallonline

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.