【问题标题】:Error while generating access_token using Ebay 's REST API - Python requests使用 Ebay 的 REST API 生成 access_token 时出错 - Python 请求
【发布时间】:2019-03-07 08:32:40
【问题描述】:

我首先尝试使用 ebay REST-API。我只是尝试使用客户端凭据授权请求生成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()

我的哪些配置不正确?谢谢。

【问题讨论】:

    标签: rest python-requests ebay-api


    【解决方案1】:

    你是 base64encoding “Basic”,不应该。 文档说只需对您的客户端 ID +“:”+客户端密码进行编码,并留下“基本”一词及其后面的空格。

    【讨论】:

      【解决方案2】:

      在您的代码中,我可以看到沙盒端点 URI,但在请求正文范围内,您使用的是生产 URL,而不是沙盒

      【讨论】:

      • 似乎这不是问题的原因,因为我仍然收到同样的错误:(
      猜你喜欢
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-05
      • 2020-11-08
      • 2018-05-25
      • 1970-01-01
      相关资源
      最近更新 更多