我正在与亚马逊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)
)
是的,您需要循环10次并附加一个数组或对象。AWS文档说ItemPage
实际上是结果页面,所以您只需要浏览它10次就可以得到100个结果。
AWS Documentation on ItemPage
:
$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
}
我们可以使用制造商参数和BrowseNode一起检索特定类别中的100多个产品。