【问题标题】:eBay Oauth token - unable to exchange authorization code for a User access tokeneBay Oauth 令牌 - 无法交换用户访问令牌的授权代码
【发布时间】:2021-02-14 19:22:33
【问题描述】:

我收到 {"error":"invalid_client","error_description":"client authentication failed"} 401 响应。 我确实设法通过手动访问网址并登录到我的帐户来获得用户同意(文档: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"}

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

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

【问题讨论】:

    标签: python-3.x api python-requests ebay-api


    【解决方案1】:

    尝试以下:

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

    【讨论】:

      【解决方案2】:

      我遇到了问题,但现在已经将它们排序并使用 drupal 模块来获取我的访问令牌。我已在 apiauth.net 上将此作为服务提供。让我知道是否有任何帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-30
        • 2023-04-06
        • 2019-06-02
        • 2017-09-28
        • 2020-07-01
        • 2011-08-05
        • 1970-01-01
        • 2013-08-17
        相关资源
        最近更新 更多