eBay大中华区API开发者平台 开发者专区

搜 索
首页>API开发者平台>技术文档>使用PHP工具包的PHP5例程: 通过PHP调用GetSearchResults

技术文档

问题
使用PHP工具包的PHP5例程: 通过PHP调用GetSearchResults
解答
0
人觉得答案有帮助)

总述

下列代码演示了如何使用eBay Accelerator Toolkit for PHP调用GetSearchResults API。更多信息请参阅 Support for the Accelerator Toolkit for PHP


详细描述

使用eBay Accelerator Toolkit for PHP调用GetSearchResults API。如有需要,可自行更替文件路径和eBay.config.php文件路径。

<?php
 error_reporting(E_ALL ^ E_NOTICE);

 // *** Change the paths to these files as needed ***
 require_once 'ebatns475EbatNs_ServiceProxy.php';
 require_once 'ebatns475EbatNs_Logger.php';
 require_once 'ebatns475GetSearchResultsRequestType.php';
 require_once 'ebatns475ItemType.php';
 
 // New Session and Service objects
 $session = new EbatNs_Session('config/ebay.config.php');
 $cs = new EbatNs_ServiceProxy($session);

 // Set Logging
 $logger = new EbatNs_Logger(true);
 $logger->_debugXmlBeautify = false;
 $logger->_debugSecureLogging = false;
 $cs->attachLogger($logger);
 
 // Set the Request type and all handler functions
 //#type $req GetSearchResultsRequestType
 $req = new GetSearchResultsRequestType();
 $cs->setHandler('SearchResultItemArrayType', 'handleSearchResults');
 $cs->setHandler('BuyingGuideDetailsType', 'handleBuyingGuideDetails');
 $cs->setHandler('CategoryArrayType', 'handleCategoryArray');

 // Set Detail Level
 $req->setDetailLevel($Facet_DetailLevelCodeType->ReturnAll);


 // Set the Query and other Filters
 $req->setQuery('ipod nano');
  
 // Settings for returned Categories
 //#type $cats RequestCategoriesType
 $cats = new RequestCategoriesType();
 $cats->setLevels(2);
 $cats->setMaxCategories(5);
 $cats->setMaxSubcategories(5);
 $req->setCategories($cats);
 
 // Set the Pagination
 //#type $pag PaginationType
 $pag = new PaginationType();
 $pag->setEntriesPerPage(2);
 $pag->setPageNumber(1);
 $req->setPagination($pag);

 // Make the Call
 $res = $cs->GetSearchResults($req);
 
 if ($res->getAck() != $Facet_AckCodeType->Success)
 {
  echo "Call Failure<br>";
  foreach ($res->getErrors() as $error)
  {
   echo "#" . $error->getErrorCode() . " " . htmlentities($error->getShortMessage()) . "/" . htmlentities($error->getLongMessage()) . "<br>";
  } 
 }
 else
 {
  echo "Call Successful<br>";
  //print_r($item);
 }
 
 // ---------------------- handler functions -------------------------------------------------
 function handleSearchResults($type, & $data)
 {
 echo"<br><b> Handling the SearchResultItemArray Now </b><br>";
  //#type $data SearchResultItemArrayType
  print_r($data);
 
  return false;
 }
 
 function handleBuyingGuideDetails($type, & $data)
 {
 echo"<br><b> Handling the Buying Guide Details Now </b><br>";
  //#type $data BuyingGuidDetailsType
  print_r($data);
  
  return false;
 }
 
 function handleCategoryArray($type, & $data)
 {
 echo"<br><b> Handling the Category Array Now </b><br>";
  //#type $data CategoryArrayType
  print_r($data);
  
  return false;
 }
?>


版本信息

上面例程基于此特定的API版本:

API Schema 版本  475
 Accelerator Toolkit for PHP   475

 

答案对您有帮助吗?

是,对我很有帮助
否,没解决我的问题