n1shop avatar image
n1shop asked

eBay Oauth token - unable to exchange authorization code for a User access token

I am getting {"error":"invalid_client","error_description":"client authentication failed"} 401 response. I did manage to get a user consent (docs: by accessing the url manually and logging in to my account using Python 3:

import requests, urllib, base64 
my_AppID = "someAppID"
my_Ru_Name = "someRuName"
scope = ""
scope = urllib.parse.quote_plus(scope) 

url = f"""
response_type=code& scope={scope}&"""

I printed the url string and accessed it in the browser, logged in and "consented". This page said "Authorization successfully completed." so I took the code value from the new redirected page url. After this I was unable to exchange the authorization code for a User access token:

my_CertID = "someCertID"
client_id = base64.b64encode(my_AppID.encode())
client_secret = base64.b64encode(my_CertID.encode())
auth_string = "Basic " + client_id.decode() + ":" + client_secret.decode() 

consent_code = "v%521.1%25i..................jYw" # from the page's link after logging in
consent_code = urllib.parse.quote_plus(code) 

headers = {"Content-Type": "application/x-www-form-urlencoded", "Authorization": auth_string}
data = {"grant_type": "authorization_code", "code": consent_code , "redirect_uri": Ru_Name}
url_token = ""
resp =, headers=headers, data=data)

# the response I get:
{"error":"invalid_client","error_description":"client authentication failed"}

What am I doing wrong? Is it the request part? The encoding?

I am kinda new to all this so thanks in advance!

apierroroauth2pythonoauthtokenstoken erroruser tokenauthentication failedinvalid client
10 |600

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

1 Answer

gblohm_de avatar image
gblohm_de answered

You need to assemble the string first (client id + ":" + client secret), then encode that to get the auth param.

· 2
10 |600

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

Hey, thanks for the answer.

Now I am getting :

{"error":"unsupported_grant_type","error_description":"grant type in request is not supported by the authorization server"}

client_id_and_secret = my_AppID + ":" + my_CertID
client_id_and_secret = base64.b64encode(client_id_and_secret.encode())
auth_string = "Basic " + client_id_and_secret.decode()

What am I doing wrong here?

0 Likes 0 ·

Looks good to me. I only ever used the sandbox as my application isn't done yet, but this is from my working log output (auth code truncated somewhat):


Did you refresh your auth code before calling that api? They last only 5 minutes, and while the error hints at a problem with the grant type, the ebay api is a mess, so who knows what they're returning when the code is outdated.

0 Likes 0 ·

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.