Getting An Ebay Oauth Token
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 toke
Solution 1:
Because this was such a nightmare to traverse eBays docs to find this answer, I figured i would post my function that solved this.
import requests, urllib, base64
defgetAuthToken():
AppSettings = {
'client_id':'<client_id>',
'client_secret':'<client_secret>',
'ruName':'<ruName>'}
authHeaderData = AppSettings['client_id'] + ':' + AppSettings['client_secret']
encodedAuthHeader = base64.b64encode(str.encode(authHeaderData))
headers = {
"Content-Type" : "application/x-www-form-urlencoded",
"Authorization" : "Basic " + str(encodedAuthHeader)
}
body= {
"grant_type" : "client_credentials",
"redirect_uri" : AppSettings['ruName'],
"scope" : "https://api.ebay.com/oauth/api_scope"
}
data = urllib.parse.urlencode(body)
tokenURL = "https://api.ebay.com/identity/v1/oauth2/token"
response = requests.post(tokenURL, headers=headers, data=data)
return response.json()
response = getAuthToken()
print(response)
response['access_token'] #access keys as required
response['error_description'] #if errors
Solution 2:
@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:
encodedAuthHeader = str(encodedAuthHeader)[2:len(str(encodedAuthHeader))-1]
Post a Comment for "Getting An Ebay Oauth Token"