【问题标题】:EBAY API: findItemsAdvanced How do search by keyword and category?EBAY API:findItemsAdvanced 如何按关键字和类别搜索?
【发布时间】:2012-10-31 15:08:35
【问题描述】:

一直在看EBAY api教程

http://developer.ebay.com/DevZone/finding/HowTo/GettingStarted_JS_NV_JSON/GettingStarted_JS_NV_JSON.html

但我想知道如何根据类别和关键字进行搜索。我通过使用操作findItemsAdvanced 来做到这一点,但我真的不知道在这里做什么。我一直在努力让它工作,但我得到的是一个空页面。这是html:

<html>
<head>
<title>eBay Search Results</title>
<style type="text/css">body { font-family: arial,sans-serif;} </style>
</head>
<body>
<h1>eBay Search Results</h1>
<div id="results"></div>
<script>
//Parse the response and build an HTML table to display search results
function _cb_findItemsAdvanced(root) {

      var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];
      var html = [];
      html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>');
      for (var i = 0; i < items.length; ++i) {
        var item     = items[i];
        var title    = item.title;
        var pic      = item.galleryURL;
        var viewitem = item.viewItemURL;
        var price    = item.sellingStatus[0].currentPrice[0].__value__;

        if (null != title && null != viewitem) {
          html.push('<tr><td>' + '<img src="' + pic + '" border="0">' + '</td>' +
          '<td><a href="' + viewitem + '" target="_blank">' + title + '</a></td>'+ '<td>' + price + "$" + '</td></tr>');
        }
      }
      html.push('</tbody></table>');
      document.getElementById("results").innerHTML = html.join("");

}  // End _cb_findItemsByKeywords() function
//Construct the request
//Replace MyAppID with your Production AppID
var url = "http://svcs.ebay.com/services/search/FindingService/v1";
 url += "?OPERATION-NAME=findItemsAdvanced";
 url += "&SERVICE-VERSION=1.0.0";
 url += "&SECURITY-APPNAME=AppID";
 url += "&GLOBAL-ID=EBAY-US";
 url += "&RESPONSE-DATA-FORMAT=JSON";
 url += "&callback=_cb_findItemsAdvanced";
 url += "&REST-PAYLOAD";
 url += "&categoryId=1"; // video game  
 url += "&keywords=digimon%20world%201"; // change value to game title 
 url += "&paginationInput.entriesPerPage=6"; 

//Submit the request
 s=document.createElement('script'); // create script element
 s.src= url;
 document.body.appendChild(s);
</script>

</body>
</html>

【问题讨论】:

    标签: html json ebay-api ebay-lms


    【解决方案1】:

    您的代码中有两个小错误。

    第一个是 categoryId - 在您的示例中,您指定了 categoryId=1。对于美国 eBay 网站上的视频游戏,这应该是 categoryId=139973。这应该会在您的 API 调用中为您提供结果。

    第二个问题是在第 13 行解析 API 调用时:

    var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];

    您的代码正在寻找 findItemsByKeywordsResponse,但您的 API 调用是 findItemsAdvanced - 因此您需要将 Javascript 函数中的行更改为:

    var items = root.findItemsAdvancedResponse[0].searchResult[0].item || [];

    我刚刚对此进行了测试,效果很好!

    【讨论】:

    • 你是如何获得视频游戏的 categoryId 的?无论如何都找不到它,可能是我错过了 API 中的某些内容...
    • eBay categoryId 可在此处找到:link(将 .co.uk 替换为正确的国家/地区域)这里还有一个所有 catID 的可下载电子表格:link,每周自动更新.
    猜你喜欢
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 2019-12-13
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 2013-08-09
    相关资源
    最近更新 更多