Ebay SDK函数GetCategorySpecifics – 有时工作,有时不工作。

huangapple go评论70阅读模式
英文:

Ebay SDK Function GetCategorySpecifics - sometimes work sometimes not

问题

需要帮助使用GetCategorySpecifics函数,有时它可以正常工作,有时我只会得到一个HTML回答而不是XML,即使是在相同的类别下。

这是我使用的代码:

import requests
import xml.etree.ElementTree as ET

def get_category_specifics(app_id, category_id):
    url = "https://api.ebay.com/ws/api.dll"
    headers = {
        "X-EBAY-API-SITEID": "77",  # 77代表德国eBay网站(eBay.de)
        "X-EBAY-API-CALL-NAME": "GetCategorySpecifics",
        "X-EBAY-API-COMPATIBILITY-LEVEL": "967",
        "X-EBAY-API-APP-ID": app_id,  # 在此处填入您自己的应用程序ID
    }

    xml_request = f"""
    <?xml version="1.0" encoding="utf-8"?>
    <GetCategorySpecificsRequest xmlns="urn:ebay:apis:eBLBaseComponents">
      <RequesterCredentials>
        <eBayAuthToken>XXX</eBayAuthToken>
      </RequesterCredentials>
      <CategoryID>{category_id}</CategoryID>
    </GetCategorySpecificsRequest>
    """

    response = requests.post(url, headers=headers, data=xml_request)
    response_content = ET.fromstring(response.content)

    return response_content

def print_response_content(response_content):
    print(f"Root element: {response_content.tag}")

    for child in response_content:
        if child.tag.endswith("Recommendations"):
            for item in child:
                if item.tag.endswith("NameRecommendation"):
                    for grandchild in item:
                        if grandchild.tag.endswith("Name"):
                            print(f"Item Specific Name: {grandchild.text}")





# 在此处使用您自己的应用程序ID和类别ID
app_id = "XXX"
category_id = "8720"

response_content = get_category_specifics(app_id, category_id)
print_response_content(response_content)

然后是其他代码来处理XML,如果我从API得到XML回答,这个方法是有效的。

这是我在这里的第一篇帖子,我对编程不是很了解,所以希望您能对我和我的问题宽容一些。

如果有更好的解决方案而不是eBay SDK,请告诉我。

Richard

这段代码有时可以正常工作,有时不行。相同的代码有不同的结果。90%的情况下,回答是一个HTML文件,10%的情况下,它是我想要的正确的XML文件。

英文:

help needed with GetCategorySpecifics, sometimes it works, sometimes I just get a HTML answer instead of the XML, even with the same category etc.

So heres the code I use:

import requests
import xml.etree.ElementTree as ET

def get_category_specifics(app_id, category_id):
    url = &quot;https://api.ebay.com/ws/api.dll&quot;
    headers = {
        &quot;X-EBAY-API-SITEID&quot;: &quot;77&quot;,  # 77 steht f&#252;r die deutsche eBay Seite (eBay.de)
        &quot;X-EBAY-API-CALL-NAME&quot;: &quot;GetCategorySpecifics&quot;,
        &quot;X-EBAY-API-COMPATIBILITY-LEVEL&quot;: &quot;967&quot;,
        &quot;X-EBAY-API-APP-ID&quot;: app_id,  # Ihre eigene App-ID hier einsetzen
    }

    xml_request = f&quot;&quot;&quot;
    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
    &lt;GetCategorySpecificsRequest xmlns=&quot;urn:ebay:apis:eBLBaseComponents&quot;&gt;
      &lt;RequesterCredentials&gt;
        &lt;eBayAuthToken&gt;XXX&lt;/eBayAuthToken&gt;
      &lt;/RequesterCredentials&gt;
      &lt;CategoryID&gt;{category_id}&lt;/CategoryID&gt;
    &lt;/GetCategorySpecificsRequest&gt;
    &quot;&quot;&quot;

    response = requests.post(url, headers=headers, data=xml_request)
    response_content = ET.fromstring(response.content)

    return response_content

def print_response_content(response_content):
    print(f&quot;Root element: {response_content.tag}&quot;)

    for child in response_content:
        if child.tag.endswith(&quot;Recommendations&quot;):
            for item in child:
                if item.tag.endswith(&quot;NameRecommendation&quot;):
                    for grandchild in item:
                        if grandchild.tag.endswith(&quot;Name&quot;):
                            print(f&quot;Item Specific Name: {grandchild.text}&quot;)





# Verwenden Sie Ihre eigene App-ID und Kategorie-ID hier
app_id = &quot;XXX&quot;
category_id = &quot;8720&quot;

response_content = get_category_specifics(app_id, category_id)
print_response_content(response_content)

Followed by other code to sort out the XML, this works if I get back the XML answer from the API.

This is my first post here, and Im not really that much into coding, so I hope your indulgent with me and my question.

If theres a better solution instead of the ebay SDK please let me know.

Richard

The code works from time to time. Same code different results. 90% the answer is a HTML file, 10% its the correct XML file with the data I wanted.

答案1

得分: 0

我最近几周一直在处理这个确切的问题,并且这周找到了解决办法。

在我看来,GetCategorySpecifics端点不起作用。eBay开发者论坛上存在着自2018年以来的问题。主要文档页面似乎也已经消失了。

在新的Restful API集合的Commerce APIs中,有一个getItemAspects端点,据我所知,它与GetCategorySpecifics是相同的东西。我一直在使用这个端点。

文档页面可以在这里找到:https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/getItemAspectsForCategory

英文:

I've just been dealing with this exact issue for the last couple of weeks and actually found a resolution this week.

It seems to me the GetCategorySpecifics endpoint is non functioning. There are issues in the eBay developer forum going back to 2018. Main docs page for it seems to be gone also.

In the Commerce APIs of the new Restful API's set there is a getItemAspects endpoint which is from what I can tell the same thing as GetCategorySpecifics. I've been using that instead.

Docs page can be found here: https://developer.ebay.com/api-docs/commerce/taxonomy/resources/category_tree/methods/getItemAspectsForCategory

huangapple
  • 本文由 发表于 2023年7月31日 18:26:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76802716.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定