使用Python requests获取eBay访问令牌(交换授权令牌)

5

我正在尝试使用这个指南获取访问令牌。

以下是我的主文件:

import requests

from utils import make_basic_auth_header, conf
code = '<Auth code here>'
url = "%s/identity/v1/oauth2/token" % conf('EBAY_API_PREFIX')
headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': make_basic_auth_header()
    }

data = {
    'grant_type': 'authorization_code',
    # 'grant_type': 'refresh_token',
    'state': None,
    'code': code,
    'redirect_uri': conf('EBAY_RUNAME')
}
r = requests.post(
    url,
    data=data,
    headers=headers,
)

这是make_basic_auth_header()函数:

def make_basic_auth_header():
    auth_header_payload = '%s:%s' % (conf('EBAY_APP_ID'), conf('EBAY_CERT_ID'))
    auth_header_base64 = base64.b64encode(auth_header_payload)
    auth_header = 'Basic %s' % auth_header_base64
    return auth_header

但是我在 r.json() 中得到的只有:

{u'error_description': u'request is missing a required parameter or malformed.', u'error': u'invalid_request'}

我感到沮丧 - 我做错了什么?

相关的技术问题需要更具体的信息才能提供帮助。

附加说明:我的文件包含Python2字符串,而不是Unicode。我也尝试过切换到Unicode,但没有帮助。 - Dmitry Arkhipenko
你尝试过将数据字典作为JSON格式的字符串传递吗?例如,在import json之后,使用data=json.dumps(data) - etemple1
看起来ebay链接现在是一个无效链接,我在尝试让oauth过程工作时遇到了麻烦。上面的“auth code”是什么意思? - user1991179
1个回答

4

对不起,我太愚蠢了,没有在ebay上看到复选框。这是复选框,在我点击它之后


你是传奇伙计。花了一个小时弄清楚为什么沙盒可以工作而生产环境不行。这应该在他们的文档中有所体现。点赞! - velval

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接