I’ve been working on the ebaySDK for most of the week. I’ve managed to integrate the Trading and Shopping APIs into my project. For the trading API, I was using an Auth n Auth token which has a validity of upto 18 months. The OAuth Token which I need for the Sell APIs is valid only for a day, so I’ll need to fetch it regularly before it expires.
I followed the documentation on the site and even tried looking through python repos on github but I haven’t been able to move forward as of yet. Here’s a quick snippet of my request code, What am I doing wrong?
import requests, json, base64, xmltodict
AppSettings = {
'app_id' : 'my_app_id',
'app_secret' : 'my_app_secret',
'dev_id': 'my_dev_id',
'ruName': 'the_ruName_for_my_app'
}
authHeaderData = AppSettings['app_id']+':'+AppSettings['app_secret']
encodedAuthHeader = base64.b64encode(authHeaderData)
session = requests.Session()
print encodedAuthHeader
url = 'https://api.ebay.com/identity/v1/oauth2/token'
session.headers.update({
'Content-Type':'application/x-www-form-urlencoded',
'Authorization':'Basic '+encodedAuthHeader
})
data = {
'grant_type':'client_credentials',
'redirect_uri': AppSettings['ruName'],
'scope':'https://api.ebay.com/oauth/api_scope'
}
response = session.post(url, data=data).json()
print response
The response I’m getting is:
{u'error_description': u'client authentication failed', u'error': u'invalid_client'}
I checked all the keys. I even tried to get the token via the production signin provided by ebay but to no avail. The response I got from the url provided by ebay was html and js code (No JSON or any data).
Has anybody faced a similar issue? How can I work through this? Am I making the requests wrong? Any insight is greatly appreciated
2
Answers
Because this was such a nightmare to traverse eBays docs to find this answer, I figured i would post my function that solved this.
@sunny babau
I was having the same problem as you. It was indeed caused by the b’ and a trailing ‘. After adding the following line to the code above, which removes these characters, it worked for me: