【问题标题】:Getting eBay Access Token (Exchanging auth token) with python requests使用 python 请求获取 eBay 访问令牌(交换身份验证令牌)
【发布时间】:2017-11-22 18:38:39
【问题描述】:

我正在尝试使用this guide 获取访问令牌。

这是我的主文件:

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 - 它没有帮助
  • 您是否尝试过将数据字典作为 json 格式的 str 传递?例如。在import jsondata=json.dumps(data)之后
  • 看起来 ebay 链接现在是死链接,我无法让 oauth 进程正常工作。上面的“授权码”是什么意思?

标签: python python-2.7 oauth-2.0 python-requests ebay-api


【解决方案1】:

对不起,我太笨了,我没有在 ebay 上看到勾选框。

【讨论】:

  • 你是传奇人物。花了一个小时弄清楚为什么沙盒可以正常工作而不能正常工作。这应该在他们的文档中。竖起大拇指
猜你喜欢
  • 1970-01-01
  • 2020-01-15
  • 2018-11-12
  • 2016-08-23
  • 1970-01-01
  • 1970-01-01
  • 2016-04-04
  • 1970-01-01
  • 2018-08-27
相关资源
最近更新 更多