我初学ebay。 我想使用其产品ID获取产品的详细信息。 我将使用的编程语言是php。 我已经阅读了其文档,但无法理解。
请有人给我代码示例。
<?php
$apicall ="http://svcs.ebay.com/services/search/FindingService/v1?
OPERATION-NAME=findItemsByProduct&
SERVICE-VERSION=1.0.0&
SECURITY-APPNAME=$appid&
RESPONSE-DATA-FORMAT=XML&
REST-PAYLOAD&
paginationInput.entriesPerPage=2&
productId.@type=ReferenceID&
productId=53039031";
// 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) {
...
</tr>";
}
}
// 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>";
}
?>
<!-- Build the HTML page with values from the call response -->
<html>
<head>
<title>eBay Search Results 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>
答案 0 :(得分:0)
尝试下面的代码,看看你得到了什么。然后它只是在阵列上循环打印线。
<?php
$apicall ="http://svcs.ebay.com/services/search/FindingService/v1?
OPERATION-NAME=findItemsByProduct&
SERVICE-VERSION=1.0.0&
SECURITY-APPNAME=$appid&
RESPONSE-DATA-FORMAT=XML&
REST-PAYLOAD&
paginationInput.entriesPerPage=2&
productId.@type=ReferenceID&
productId=53039031";
// Load the call and capture the document returned by eBay API
$response = simplexml_load_string( file_get_contents( $apicall ) );
//print the response
print_r( $response );
首先使用下面的chrome插件,以确保您的请求网址正确形成。
高级REST客户端 https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo
邮递员 - REST客户端 https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en