11

如何使用 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>";
       }
4

2 回答 2

7

您是否尝试过 eBay论坛中提供的最新方法?

我可以帮助解释和指导你。

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

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

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

示例 XML 文件HERE显示了pictureURLLargepictureURLSuperSize

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

$pic = $item->pictureURLLarge;

或者

$pic = $item->pictureURLSuperSize;

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

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

于 2012-05-28T04:57:32.890 回答
0

在我的情况下,它在我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";

希望它会帮助某人。

于 2020-06-17T06:42:13.903 回答