2012-05-20 48 views
10

如何使用eBay API获取大型商品图片?下面的API调用在使用galleryURL时会返回缩略图。我试着用PictureURLLarge替换它,但是没有返回一个URL。eBay API - 如何获取大型图片?

(我指的是该生产线是从底部16:$ PIC = $用品 - > GALLERYURL;)

// API request variables 
     $endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1'; // URL to call 
     $version = '1.11.0'; // API version supported by your application 
     $appid = 'XXXXX'; // Replace with your own AppID 
     $globalid = 'EBAY-US'; // Global ID of the eBay site you want to search (e.g., EBAY-DE) 
     $query = "soft thin (shirt, tshirt, t-shirt)"; // Supply your own query 
     $safequery = urlencode($query); // Make the query URL-friendly 
     $i = '0'; // Initialize the item filter index to 0 

     // Create a PHP array of the item filters you want to use in your request 
     $filterarray = 
     array(
      array(
      'name' => 'MaxPrice', 
      'value' => '1500', 
      'paramName' => 'Currency', 
      'paramValue' => 'USD'), 
      array(
      'name' => 'FreeShippingOnly', 
      'value' => 'false', 
      'paramName' => '', 
      'paramValue' => ''), 
      array(
      'name' => 'ListingType', 
      'value' => array('AuctionWithBIN','FixedPrice','StoreInventory'), 
      'paramName' => '', 
      'paramValue' => ''), 
     ); 

     // Generates an indexed URL snippet from the array of item filters 
     function buildURLArray ($filterarray) { 
     global $urlfilter; 
     global $i; 
     // Iterate through each filter in the array 
     foreach($filterarray as $itemfilter) { 
      // Iterate through each key in the filter 
      foreach ($itemfilter as $key =>$value) { 
      if(is_array($value)) { 
       foreach($value as $j => $content) { // Index the key for each value 
       $urlfilter .= "&itemFilter($i).$key($j)=$content"; 
       } 
      } 
      else { 
       if($value != "") { 
       $urlfilter .= "&itemFilter($i).$key=$value"; 
       } 
      } 
      } 
      $i++; 
     } 
     return "$urlfilter"; 
     } // End of buildURLArray function 

     // Build the indexed item filter URL snippet 
     buildURLArray($filterarray); 

     // Construct the findItemsAdvanced HTTP GET call 
     $apicall = "$endpoint?"; 
     $apicall .= "OPERATION-NAME=findItemsAdvanced"; 
     $apicall .= "&SERVICE-VERSION=$version"; 
     $apicall .= "&SECURITY-APPNAME=$appid"; 
     $apicall .= "&GLOBAL-ID=$globalid"; 
     $apicall .= "&descriptionSearch=true"; 
     $apicall .= "&categoryId=110"; 
     $apicall .= "&keywords=$safequery"; 
     $apicall .= "&paginationInput.entriesPerPage=100"; 
     $apicall .= "$urlfilter"; 

     // Load the call and capture the document returned by eBay API 
     $resp = simplexml_load_file($apicall); 

     // Check to see if the request was successful, else print an error 
     if ($resp->ack == "Success") { 
     $results = ''; 
     // If the response was loaded, parse it and build links 
     foreach($resp->searchResult->item as $item) { 
      $pic = $item->galleryURL; 
      $link = $item->viewItemURL; 
      $title = $item->title; 
      $ship = (float) $item->shippingInfo->shippingServiceCost; 
      $price = (float) $item->sellingStatus->currentPrice; 
      $sell = ($ship + $price); 

      // For each SearchResultItem node, build a link and append it to $results 
      $results .= "<a href=\"$link\" title=\"$title\" target=\"_blank\"><div class=\"shirt-block\"><img src=\"$pic\" width=\"200\" height=\"200\"><br /><br /><span class=\"cost\">$$sell</span></div></a>"; 
     } 
     } 
     // If the response does not indicate 'Success,' print an error 
     else { 
     $results = "<h3>Oops! The request was not successful. Make sure you are using a valid "; 
     $results .= "AppID for the Production environment.</h3>"; 
     } 
+0

你能'的var_dump($项目)'的循环?另外,你是否尝试过'$ item-> pictureURLLarge'(区分大小写)? –

+1

我发现了这个问题,它确实很愚蠢。将描述搜索设置为“true”会禁用使用outputSelector的功能,让您获取pictureURLLarge。我不知道为什么......让我想哭。 – Carson

回答

7

你尝试在易趣Forum?

提供的最新方法

我可以帮助解释和指导。

也就是说成员建议,包括$apicall .= "&outputSelector=$outputSelector";在您的findItemsAdvanced要求的结构。

此时我会检查返回的XML文件以查看它是否通过Firebug包含(单击NET选项卡,然后单击下面的XHR)。在Chrome中,只需启用开发人员工具,然后单击NETWORK选项卡即可查看返回的XML文件。点击文件展开,您将看到没有空白的内容。

因为XML文件不会是漂亮,复制内容然后将其粘贴HERE美化它的可读性。同时具有pictureURLLarge并显示pictureURLSuperSize

示例XML文件HERE

一旦你验证了大图像的URL已经包含在XML文件中,第二步是然后用它在你的标记,像这样:

$pic = $item->pictureURLLarge; 

$pic = $item->pictureURLSuperSize; 

对不起我没有我自己的易趣的AppID测试及其API游乐场链路中断,但可以进一步帮助是什么,目前还不清楚。

可以肯定的,则第一步是获得大图象请求和第二步骤是简单地使用该图像。

+0

感谢您的努力。对不起,不早回复,但我一直在墨西哥没有互联网连接。我已经尝试过你上面说的,但是当我使用萤火虫时,我没有看到一个xml文件。该网站是:http://shirtcake.com/也许你可以看到更多的东西呢? – Carson

+0

由于您有第二个标签,所以关闭主体标签的第一个实例应该被删除。在第一个关闭body标签下是jQuery v1.71的另一个实例,而以前如果向北看,则会安装v1.6.4。我没有看到任何形式的请求,也没有看到您发布的上述标记。它在哪里? – arttronics

+0

嗯,也许他们是你使用的PHP进程的错误。这[易趣教程](http://developer.ebay。com/devzone/finding/HowTo/PHP_SearchInterm_NV_XML/PHP_SearchInterm_NV_XML.html)具有可下载的项目文件和确保PHP进程正确的分步说明,即服务器端。还有一些示例PHP文件显示与您相似的标记,以帮助创建/设置PHP流程以实现其建议。这有帮助吗? – arttronics