如何使用php访问Amazon api中超过10个项目的详细信息?

前端之家收集整理的这篇文章主要介绍了如何使用php访问Amazon api中超过10个项目的详细信息?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用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)
)
是的,您需要循环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","ItemPage"=>$i,"Keywords" => $search);

    $results[] = $obj->searchProducts($parameters);

}

foreach ($results as $r) {
    //do your stuff
}
原文链接:https://www.f2er.com/php/133848.html

猜你在找的PHP相关文章