07-24-2024 09:44 AM
I was able to get "code" using client_id and redirect_uri successfully. But when I try to use this "code" while sending request to "authorization_code" endpoint I got error below.
Error:
{'error': 'invalid_grant', 'error_description': 'the provided authorization grant code is invalid or was issued to another client'}
Here is the python script;
import urllib.parse
import requests
import base64
if __name__ == '__main__':
codes = input("Enter code:").strip()
codes = urllib.parse.unquote(codes)
client_id = "XXXXXX"
client_secret = "XXXXXX"
exhange_end_point = "https://api.ebay.com/identity/v1/oauth2/token"
ci_cs = f"{client_secret}:{client_secret}"
encoded_ci_cs = ci_cs.encode()
b64_ci_cs = base64.b64encode(encoded_ci_cs).decode()
headers = {
"Content-Type" : "application/x-www-form-urlencoded",
"Authorization" : "Basic " + b64_ci_cs
}
data = {
"grant_type" : "authorization_code",
"code" : codes,
"redirect_uri" : "XXXXXXX"
}
resp = requests.post(exhange_end_point, headers= headers, data = data)
print(resp.json())