【发布时间】:2019-04-30 06:16:29
【问题描述】:
我目前在使用 OAuth 方法获取授权代码授予流程的令牌时遇到问题。我正在开发一个 python 应用程序,以便在我的 eBay 商店上自动化某些功能。我已经设法通过客户端凭据授予流程获得访问权限,但就我而言,授权还不够。
我现在想通过授权码授予流程获取访问令牌,但我无法在第一步(“从文档中获得第三方的同意”)中获取授权码。我试图在我的浏览器中获取这个授权码,然后在我的应用程序中使用它,但是我有一个安全错误告诉我这个令牌已经被使用了,这很安全。
我知道我需要发送我的凭据以获取此授权代码,但我不知道如何处理用户授予权限的 redirectUrl。这是我所做的:
def GetAuthToken():
headers = {
'client_id' : 'xxxxxxx',
'redirect_uri' : 'xxxxx',
'response_type' : 'code',
'scope' : 'https://api.ebay.com/oauth/api_scope/sell.inventory',
}
tokenURL = 'https://auth.ebay.com/oauth2/authorize'
response = requests.get(tokenURL, headers=headers)
print(response)
authDict = response.json()
print(authDict)
GetAuthToken()
我收到了这个错误:
Response [200]
{'error_id': 'unauthorized_client', 'error_description': 'The OAuth client was not found.', 'http_status_code': 401}
鉴于 API 正在等待凭据,这是正常的。我的问题是:如何进行身份验证才能使用我的 python 程序获取此授权代码?在文档 (https://developer.ebay.com/api-docs/static/oauth-consent-request.html) 中,它指定用户需要手动登录才能获得第一步授权码。但是,我需要自动执行此身份验证。
我应该如何将凭据参数发送到 API 以便自动执行此步骤?
我目前正在浏览 Python OAuth2 库,看看我能用它做什么,我很确定它会有所帮助。如果我能找到自动化的方法,我会通知你们。
无论如何,提前感谢您的支持! :)
【问题讨论】:
标签: python-3.x oauth-2.0 automation token ebay-api