【发布时间】:2021-12-03 17:17:18
【问题描述】:
我正在开展一个需要访问 eBay 产品 API 的项目。我正在使用
getProductDetails 调用试图获取包含 eBay 识别号的字段(例如 ePID、ISBN、GTIN 等)。
我尝试了两种方法来获取此调用以生成我需要的字段,但我只得到“成功”返回,但没有其他 Python 方法的详细信息和 XML 方法的 500 html 响应。到目前为止,我尝试过的两种方法(XML 和 Python)都在下面的工作示例中。我从 Ebay 获得的密钥是:appid、cevid、certid 和 token,它们保存在与我的代码文件相同的目录下的 .env 文件中。
我花了好几天的时间盯着不完整的 EBay API 文档,以及指向 EBay SDK package 的 EBay 客户支持,它不与产品 API 接口。
这是 Python GET 请求方法:
root = 'https://svcs.ebay.com'
endpoint = '/services/marketplacecatalog/ProductService/v1'
headers = {'X-EBAY-API-IAF-TOKEN': 'Bearer ' + OAuth,
'Content-Type': 'application/x-www-form-urlencoded',
'X-EBAY-SOA-RESPONSE-DATA-FORMAT':'JSON',
'X-EBAY-SOA-SECURITY-APPNAME': AppID}
params = {'X-EBAY-SOA-OPERATION-NAME': 'getProductDetails',
'productDetailsRequest':'[0..*]',
'productDetailsRequest.productIdentifier.ePID':'EPID'+’115115562893’} #example ePID
r = requests.get(root+endpoint, headers=headers, params=params)
我希望输出带有产品详细信息,尤其是 GTIN 和其他标识符,但我得到了:
{'getProductDetailsResponse': [{'ack': ['Success'],
'version': ['1.3.1'],
'timestamp': ['2021-12-02T17:34:18.510Z']}]}
使用 XML POST 方法,代码为:
root = 'https://svcs.ebay.com'
endpoint = '/services/marketplacecatalog/ProductService/v1'
target_url = root + endpoint
xml_request = """<?xml version="1.3.1" encoding="utf-8"?>
<getProductDetailsRequest>
<productDetailsRequest>
<productIdentifier>
<ePID>EPID115115562893</ePID> #random ePID number
</productIdentifier>
<dataset>DisplayableProductDetails</dataset>
</productDetailsRequest>
</getProductDetailsRequest>"""
headers = {'X-EBAY-API-IAF-TOKEN': 'Bearer ' + OAuth,
'Content-Type': 'application/x-www-form-urlencoded',
'Version': '1.3.1',
'X-EBAY-SOA-RESPONSE-DATA-FORMAT':'JSON',
'X-EBAY-SOA-SECURITY-APPNAME': AppID}
r = requests.post(target_url, data=xml_request, headers=headers)
但是这会产生 500 HTTP 响应。
如有任何帮助,请致电返回 eBay 产品标识号(ePID、ISBN、GTIN 等),我将不胜感激。谢谢
【问题讨论】:
标签: python xml python-requests ebay-api