eBay API - How to get large item pictures?
Asked Answered
N

2

11

How do I get a large item image using the eBay API? The API call below returns a thumbnail image when I use galleryURL. I tried replacing it with PictureURLLarge, but that did not return a URL.

(The line I am referring to is 16th from the bottom: $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>";
       }
Neuromuscular answered 20/5, 2012 at 1:21 Comment(2)
Can you var_dump($item) in the loop? Also, did you try $item->pictureURLLarge (case sensitive)?Bayern
I discovered the problem, and it is really stupid. Setting the description search as "true" disables the ability to use the outputSelector that let's you get the pictureURLLarge. I don't know why...makes me want to cry.Neuromuscular
A
7

Did you try the most recent method provided in the eBay Forum?

I can help to explain and guide you.

That member suggests to include $apicall .= "&outputSelector=$outputSelector"; in your construct of the findItemsAdvanced request.

At that point I would check the XML File returned to see if it's included via Firebug (click the NET tab, then XHR below). In Chrome, just enable Developer Tools and click the NETWORK tab to see returned XML File. Click file to expand and you will see contents without whitespace.

Because the XML file is not going to be pretty, copy that content then paste it HERE to beautify it for readability.

Sample XML file HERE that has both pictureURLLarge and pictureURLSuperSize shown.

Once you verify that the URL for large image has been included in your XML file, second step is to then use it in your markup like so:

$pic = $item->pictureURLLarge;

or

$pic = $item->pictureURLSuperSize;

Sorry I do not have my own eBay AppID to test and their API Playground link is broken but can assist further is anything is unclear.

To be sure, the first step is to obtain the Large Image request and the second step is to simply use the image.

Anticathode answered 28/5, 2012 at 4:57 Comment(9)
Thank you for your efforts. Sorry for not replying sooner, but I have been in Mexico with no internet connection. I have tried what you say above, but I do not see an xml file when I use firebug. The website is: shirtcake.com Maybe you can see something more there?Neuromuscular
The first instance of the closing body tag should be removed since you have a second one. Under that first closing body tag is another instance of jQuery v1.71 while previously you have v1.6.4 installed if you look north. I do not see any kind of request to ebay being made nor do I see any of the above markup you posted. Where is it?Anticathode
Hum, perhaps their is an error with the PHP process your using. This eBay tutorial has downloadable project files and step-by-step instructions for making sure PHP process is correct, server side. There is also example PHP files showing markup similar to yours to aid in creating/setting up the PHP process to their recommendations. Does this help?Anticathode
If I remove the outputSelector language and use galleryURL in place of pictureURLLarge the photos show up just fine (except they are low resolution)...see here: shirtcake.comNeuromuscular
If the above eBay tutorial on PHP is something to complicated or time consuming to learn, perhaps you can use the eBay JavaScript API instead. That allows you to perform the same tasks client side. At the same time, it makes debugging easier since both you and I can view incoming and outgoing requests, unlike server side PHP API is doing which is accessible only to you. Here is the link to eBay JavaScript API. Consider using this API instead if it's possible. Does this help?Anticathode
I discovered the problem, and it is really stupid. Setting the description search as "true" disables the ability to use the output selector that let's you get the pictureURLLarge I don't know why...Neuromuscular
It's the simple things that can make a difference. I did read a little bit about how, depending on settings, eBay will use different database to retrieve request. That's why step 1 was to see if it was ever returned... and take it from there if it wasn't seen. Glad to hear the image is now received and used in your webpage.Anticathode
Actually, i can't use the large image because I need description search!Neuromuscular
What if your did two queries? First to get the image URL, save that URL info, then do a description search as needed? That said, the first instance can just be for the image while the second instance provides all the other info.Anticathode
B
0

In my case it worked after I passed outputSelector as an array to the GET request:

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

But, I was using findItemsByKeywords. Here is the full request.

 $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";

Hope it will help someone.

Betroth answered 17/6, 2020 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.