我正在尝试使用ebay REST-API作为第一个。我只是尝试使用客户端凭据grant-request生成access_token
。我按照https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html的说明进行操作
HTTP method: POST
URL (Sandbox): https://api.sandbox.ebay.com/identity/v1/oauth2/token
HTTP headers:
Content-Type = application/x-www-form-urlencoded
Authorization = Basic <B64-encoded_oauth_credentials>
Request body (wrapped for readability):
grant_type=client_credentials&
redirect_uri=<RuName-value>&
scope=https://api.ebay.com/oauth/api_scope
我收到此错误:{'error': 'invalid_client', 'error_description': 'client authentication failed'}
和我的代码如下所示:
path = 'https://api.sandbox.ebay.com/'
app_json = 'application/json'
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': base64.b64encode(b'Basic CLIENT_ID:CLIENT_SECRET')
}
payload = 'grant_type=client_credentials&redirect_uri=Searchez&scope=https://api.ebay.com/oauth/api_scope'
def get_oath_token():
url = 'https://api.sandbox.ebay.com/identity/v1/oauth2/token'
r = requests.post(url, headers=headers, data=payload)
print(r.json())
get_oath_token()
我的配置错误了什么?谢谢。
你是base64编码“基本”,不应该。该文档说只是编码您的客户端ID +“:”+客户端密钥,并保留单词“基本”和单独的空格。
在您的代码中,我可以看到沙箱端点URI,但在请求正文范围中,您使用了生产URL而不是沙箱