<?php
error_reporting(E_ALL);
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1';
$query = 'harry potter';
$filterarray =
array(
array(
'name' => 'MaxPrice',
'value' => '25',
'paramName' => 'Currency',
'paramValue' => 'USD'),
array(
'name'=> 'FreeShippingOnly',
'value'=>'true',
'paramName'=>'',
'paramValue'=>''),
array(
'name'=>'ListingType',
'value' => array('AuctionWithBIN','FixedPrice','StoreInventory'),
'paramName' => '',
'paramValue' => ''),
);
function buildXMLFilter ($filterarray){
global $xmlfilter;
foreach ($filterarray as $itemfilter){
$xmlfilter .= "<itemFilter>\n";
foreach($itemfilter as $key => $value){
if(is_array($value)){
foreach($value as $arrayval){
$xmlfilter .= " <$key>$arrayval</key>\n";
}
}
else {
if($value != ""){
$xmlfilter .= " <$key>$value</$key>\n";
}
}
}
$xmlfilter .= "</itemFilter>\n";
}
return "$xmlfilter";
}
buildXMLFilter($filterarray);
$resp = simplexml_load_string(constructPostCallAndGetResponse($endpoint, $query, $xmlfilter));
if ($resp->ack == "Success"){
$result = '';
foreach($resp->searchResult->item as $item){
$pic = $item->gallaryURL;
$link = $item->viewItemURL;
$title = $item->title;
$results .= "<tr><td><img src=\"$pic\"></td><td><a href=\"$link\">$title</a></td></tr>";
}
} else {
$results = "<h3>Ops! The request was not successful. Make sure you are using a vlid ";
$results .= "AppId for the Production environment.</h3>";
}
?>
<html>
<head>
<title>search result for <?php echo $query; ?></title>
<style type="text/css">
body {
font-family:arial,sans-serif;
}
</style>
</head>
<body>
<h1>ebay search results for <?php echo $query; ?></h1>
<table>
<tr>
<td>
<?php echo $results;?>
</td>
</tr>
</table>
</body>
</html>
<?php
function constructPostCallAndGetResponse($endpoint, $query, $xmlfilter){
global $xmlrequest;
$xmlrequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$xmlrequest .= "<findItemsByKeywordsRequest xmlns=\"http:://www.ebay.com/marketplace/search/v1/services\">\n";
$xmlrequest .= "<keywords>";
$xmlrequest .= $query;
$xmlrequest .= "</keywords>\n";
$xmlrequest .= $xmlfilter;
$xmlrequest .= "<paginationInput>\n <entriesPerPage>3</entriesPerPage>\n</paginationInput>\n";
$xmlrequest .= "</findItemsByKeywordsRequest>";
$headers = array(
'X-EBAY-SOA-OPERATION-NAME: findItemsByKeywords',
'X-EBAY-SOA-SERVICE-VERSION: 1.3.0',
'X-EBAY-SOA-REQUEST-DATA-FORMAT: XML',
'X-EBAY-SOA-GLOBAL-ID: EBAY-US',
'X-EBAY-SOA-SECURITY-APPNAME: ',
'Content-Type: text/xml;charset=utf-8',
);
$session = curl_init($endpoint);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_POSTFIELDS, $xmlrequest);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$responsexml = curl_exec($session);
curl_close($session);
return $responsexml;
}
?>
ebay search results for harry potter
Ops! The request was not successful. Make sure you are using a vlid AppId for the Production environment.
上手くいかない。。。
期待値は下記のようなインターフェイス