加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 17:52:46 所属栏目:PHP教程 来源:网络整理
导读:我正在使用amazon api并使用了来自在线资源 http://www.codediesel.com/php/accessing-amazon-product-advertising-api-in-php/的代码. 当我使用amazon api进行搜索查询时,我想获得超过10个产品的详细信息.我知道每次调用获得10个数据的amazon api策略,但是
我正在使用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
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读