【问题标题】:eBay API - How to get large item pictures?eBay API - 如何获取大件商品图片?
【发布时间】:2012-05-20 01:21:32
【问题描述】:

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

(我指的行是倒数第 16 行:$pic = $item->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>";
       }

【问题讨论】:

  • 你能在循环中var_dump($item) 吗?另外,您是否尝试过$item-&gt;pictureURLLarge(区分大小写)?
  • 我发现了这个问题,真的很蠢。将描述搜索设置为“true”会禁用使用 outputSelector 来获取图片 URLLarge 的功能。我不知道为什么……让我想哭。

标签: php ebay-api


【解决方案1】:

您是否尝试过 eBay 提供的最新方法Forum?

我可以帮你解释和指导。

该成员建议在 findItemsAdvanced 请求的构造中包含 $apicall .= "&amp;outputSelector=$outputSelector";

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

因为 XML 文件不会很漂亮,所以复制该内容,然后将其粘贴到HERE 以美化它以提高可读性。

同时显示 pictureURLLargepictureURLSuperSize 的示例 XML 文件 HERE

一旦您确认大图像的 URL 已包含在您的 XML 文件中,第二步就是在您的标记中使用它,如下所示:

$pic = $item->pictureURLLarge;

$pic = $item->pictureURLSuperSize;

抱歉,我没有自己的 eBay AppID 可供测试,并且他们的 API Playground 链接已损坏,但如果有任何不清楚的地方,可以进一步提供帮助。

可以肯定的是,第一步是获取大图请求,第二步是简单地使用图片。

【讨论】:

  • 感谢您的努力。很抱歉没有早点回复,但我在墨西哥没有互联网连接。我已经尝试过你上面所说的,但是当我使用 firebug 时我没有看到 xml 文件。网站是:shirtcake.com也许你可以在那里看到更多的东西?
  • 第一个结束body标签的实例应该被移除,因为你有第二个。在第一个结束的 body 标记下是另一个 jQuery v1.71 实例,而之前如果你向北看,你已经安装了 v1.6.4。我没有看到对 ebay 的任何请求,也没有看到您发布的上述任何标记。它在哪里?
  • 嗯,可能是你使用的PHP进程出错了。这个eBay tutorial 具有可下载的项目文件和分步说明,用于确保 PHP 进程在服务器端正确。还有一些示例 PHP 文件显示类似于您的标记,以帮助创建/设置 PHP 流程以符合他们的建议。这有帮助吗?
  • 如果我删除 outputSelector 语言并使用galleryURL 代替pictureURLLarge,照片显示得很好(除了它们是低分辨率)...请参阅此处:shirtcake.com
  • 如果上面关于 PHP 的 eBay 教程学习起来很复杂或耗时,也许您可​​以使用 eBay JavaScript API 代替。这使您可以在客户端执行相同的任务。同时,它使调试更容易,因为您和我都可以查看传入和传出请求,这与服务器端 PHP API 所做的不同,只有您可以访问。这是eBay JavaScript API 的链接。如果可能,请考虑使用此 API。这有帮助吗?
【解决方案2】:

在我将outputSelector 作为数组传递给GET 请求后,它就起作用了:

 $apiCall .= "&outputSelector(0)=PictureURLLarge";
 $apiCall .= "&outputSelector(1)=PictureURLSuperSize";
 $apiCall .= "&outputSelector(2)=GalleryInfo";

但是,我使用的是findItemsByKeywords。这是完整的请求。

 $apiCall = "https://svcs.ebay.com/services/search/FindingService/v1?";
 $apiCall .= "OPERATION-NAME=findItemsByKeywords";
 $apiCall .= "&SERVICE-VERSION=1.0.0";
 $apiCall .= "&SECURITY-APPNAME=PASTE-APP-ID-HERE";
 $apiCall .= "&GLOBAL-ID=EBAY-GB";
 $apiCall .= "&keywords=" . urlencode($keywords);
 $apiCall .= "&outputSelector(0)=PictureURLLarge";
 $apiCall .= "&outputSelector(1)=PictureURLSuperSize";
 $apiCall .= "&outputSelector(2)=GalleryInfo";
 $apiCall .= "&RESPONSE-DATA-FORMAT=XML";
 $apiCall .= "&REST-PAYLOAD";
 $apiCall .= "&paginationInput.pageNumber=1";
 $apiCall .= "&paginationInput.entriesPerPage=100";

希望对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多