eBay API 返回低分辨率缩略图,而不是卖家上传的图像



当使用eBay的API时,列表使用低分辨率缩略图图片显示,而不是卖家上传的高分辨率版本。我必须在代码中更改什么才能解决此问题?我已经在eBays API论坛上查看了解决方案,但它似乎与教程中使用的代码无关。

Javascript代码:

<div id="api"></div>
<script>
function _cb_findItemsByKeywords(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;
    if (null != title && null != viewitem)
    {
      html.push(
        '<tr id="api_microposts"><td>'
         + '<img src="' + pic + '" border="0" width="190">' + '<a href="' + viewitem + '" target="_blank">' + title + 
         '</a></td></tr>');
    }
  }
  html.push('</tbody></table>');
  document.getElementById("api").innerHTML = html.join("");
}

// Create a JavaScript array of the item filters you want to use in your request
var filterarray = [
  {"name":"MaxPrice",
   "value":"500",
   "paramName":"Currency",
   "paramValue":"USD"},
   {"name":"MinPrice",
   "value":"200",
   "paramName":"Currency",
   "paramValue":"USD"},
  {"name":"FreeShippingOnly",
   "value":"true",
   "paramName":"",
   "paramValue":""},
  {"name":"ListingType",
   "value":["FixedPrice"],
   "paramName":"",
   "paramValue":""},
  ];
// Define global variable for the URL filter
var urlfilter = "";

// Generates an indexed URL snippet from the array of item filters
function  buildURLArray() {
  // Iterate through each filter in the array
  for(var i=0; i<filterarray.length; i++) {
    //Index each item filter in filterarray
    var itemfilter = filterarray[i];
    // Iterate through each parameter in each item filter
    for(var index in itemfilter) {
      // Check to see if the parameter has a value (some don't)
      if (itemfilter[index] !== "") {
        if (itemfilter[index] instanceof Array) {
          for(var r=0; r<itemfilter[index].length; r++) {
          var value = itemfilter[index][r];
          urlfilter += "&itemFilter(" + i + ")." + index + "(" + r + ")=" + value ;
          }
        }
        else {
          urlfilter += "&itemFilter(" + i + ")." + index + "=" + itemfilter[index];
        }
      }
    }
  }
}  // End buildURLArray() function
// Execute the function to build the URL filter
buildURLArray(filterarray);


</script>

<!--
Use the value of your appid for the appid parameter below.
-->
<script src=http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=*APPNAME*&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&keywords=iphone%205%2016gb%20unlocked&paginationInput.entriesPerPage=3>
</script>

默认情况下,查找 API 返回 140 像素的缩略图。您必须在 API 调用中指定outputSelector才能检索更大的缩略图(400px 或 800px)。将outputSelector=PictureURLLargeoutputSelector=PictureURLSuperSize添加到调用应使其返回较大图像的 URL。

我也为此挣扎了很长时间。 进行以下更改:

  1. item.galleryURL; 替换为 item.pictureURLSuperSize;
  2. Add &outputSelector=PictureURLSuperSizeright after &paginationInput.entriesPerPage=3

这应该可以解决问题。 确保使用相同的大写结构。
我写了一篇更长的博客文章,这里有更多例子

最新更新