eBay Oauth令牌-无法为用户访问令牌交换授权代码



我得到{"error":"invalid_client","error_description":"client authentication failed"} 401响应。我确实设法通过手动访问url并登录到我的帐户来获得用户同意(docs: https://developer.ebay.com/api-docs/static/oauth-authorization-code-grant.html):

import requests, urllib, base64
my_AppID = "someAppID"
my_Ru_Name = "someRuName"
scope = "https://api.ebay.com/oauth/api_scope/sell.fulfillment"
scope = urllib.parse.quote_plus(scope)
url = f"""https://auth.ebay.com/oauth2/authorize?
client_id={my_AppID}&
redirect_uri={my_Ru_Name}&
response_type=code&
scope={scope}&"""

我打印了url字符串并在浏览器中访问它,登录并"同意"。此页面显示"授权成功完成"。所以我从新的重定向页面url中获取代码值。在此之后,我无法将授权代码交换为用户访问令牌:

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 = "https://api.ebay.com/identity/v1/oauth2/token"
resp = requests.post(url_token, headers=headers, data=data)
print(resp.text)
# the response I get:
{"error":"invalid_client","error_description":"client authentication failed"}

我做错了什么?是请求部分吗?的编码?

我对这一切都有点陌生,所以提前感谢!

尝试如下:

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

我遇到了问题,但现在已经把它们排序,并使用drupal模块来获得我的访问令牌。我已经在apiauth.net上提供了这个服务。如果有什么帮助,请告诉我。

consent_code为url编码。你需要解码它(使用在线服务)。

url编码的代码看起来像这样:v%5E1.1%23i%5E1%23f%5E0%23r…——这是错误的。After urldecode它看起来像这样:v ^ 1.1 # ^ 1 # f r ^ ^ 0 # 1 # p ^ 3 #我^ 3…

最新更新