我正在使用amazon api,并使用了来自在线资源http://www.codediesel.com/php/accessing-amazon-product-advertising-api-in-php/的代码。
当我使用amazon api进行搜索查询时,我想获得超过10个产品的详细信息。我知道每次调用获取10个数据的amazon api策略,但是可以通过创建循环或其他东西来获取更多数据吗?
当我提出请求时,我已经分配了以下参数
$parameters = array("Operation" => "ItemSearch",
"SearchIndex" => "Electronics",
"ResponseGroup" => "Images,ItemAttributes,EditorialReview,Offers ",
"ItemPage"=>"10",
"Keywords" => $search );
所以即使我要求10页的结果,我也不确定如何显示每个页面(1到10)的数据,所以在我查询时总共得到100个项目。当我尝试运行代码时,我得到以下响应:
SimpleXMLElement Object (
[Request] => SimpleXMLElement Object (
[IsValid] => True
[ItemSearchRequest] => SimpleXMLElement Object (
[ItemPage] => 10
[Keywords] => laptop
[ResponseGroup] => Array (
[0] => Images
[1] => ItemAttributes
[2] => EditorialReview
[3] => Offers
)
[SearchIndex] => Electronics
)
)
[TotalResults] => 3383691
[TotalPages] => 338370
[MoreSearchResultsUrl] => http://www.amazon.co.uk/gp/redirect.html?camp=2025&creative=12734&location=http%3A%2F%2Fwww.amazon.co.uk%2Fgp%2Fsearch%3Fkeywords%3Dlaptop%26url%3Dsearch-.................(and on)
)
答案 0 :(得分:4)
是的,您需要循环10次并附加数组或对象。 AWS文档说ItemPage
实际上是结果页面,因此您只需要翻阅10次以获得100个结果。
ItemPage
上的AWS文档:
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/PagingThroughResults.html
$obj = new AmazonProductAPI();
$results = array();
for ($i=1;$i<=10;$i++) {
$parameters = array("Operation" => "ItemSearch",
"SearchIndex" => "Electronics",
"ResponseGroup" => "Images,ItemAttributes,EditorialReview,Offers ",
"ItemPage"=>$i,
"Keywords" => $search);
$results[] = $obj->searchProducts($parameters);
}
foreach ($results as $r) {
//do your stuff
}
答案 1 :(得分:-1)
我们可以使用manufacturer参数和BrowseNode来检索特定类别中的100多种产品。