亚马逊XML:搜索产品并返回包括价格在内的结果

时间:2013-01-30 07:06:19

标签: php xml-parsing amazon-web-services amazon

我正在尝试做一件非常简单的事情,我只需要在亚马逊中搜索并返回包含产品,描述和价格的XML。 这是我发送的最终地址:

http://webservices.amazon.com/onca/xml?AWSAccessKeyId=[MYKEYID]&AssociateTag=[MYASSOCIATION-TAG]&Keywords=Wireless%2520headset%2520xbox&Operation=ItemSearch&ReponseGroup=Full&SearchIndex=ALL&Service=AWSECommerceService&Timestamp=2013-01-29T21%3A04%3A49Z&Version=2011-08-01&Signature=[MY SIGNATURE]

我几乎得到除价格以外的所有东西:

<XML .... >
<item>...</item>
<Item><ASIN>B003ZSP0WW</ASIN><ParentASIN>B001ELJPOQ</ParentASIN><DetailPageURL>http://www.amazon.com/Xbox-360-Wireless-Controller-Glossy-Black/dp/B003ZSP0WW%3FSubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB003ZSP0WW</DetailPageURL><ItemLinks><ItemLink><Description>Technical Details</Description><URL>http://www.amazon.com/Xbox-360-Wireless-Controller-Glossy-Black/dp/tech-data/B003ZSP0WW%3FSubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>Add To Baby Registry</Description><URL>http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3DB003ZSP0WW%26SubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>Add To Wedding Registry</Description><URL>http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3DB003ZSP0WW%26SubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>Add To Wishlist</Description><URL>http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3DB003ZSP0WW%26SubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>Tell A Friend</Description><URL>http://www.amazon.com/gp/pdp/taf/B003ZSP0WW%3FSubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>All Customer Reviews</Description><URL>http://www.amazon.com/review/product/B003ZSP0WW%3FSubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>All Offers</Description><URL>http://www.amazon.com/gp/offer-listing/B003ZSP0WW%3FSubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink></ItemLinks><ItemAttributes><Manufacturer>Microsoft Software</Manufacturer><ProductGroup>Video Games</ProductGroup><Title>Xbox 360 Wireless Controller - Glossy Black</Title></ItemAttributes>
</Item>

请帮助,我该怎么做才能看到产品价格?从亚马逊解析价格的任何更容易的方式?

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试将&ReponseGroup=Full更改为&ReponseGroup=Large,您将获得整个数据,但也包括价格。它将以attaributes标记。

注意:尝试将其更改为&ReponseGroup=Small您将获得较少的数据,但我不确定价格是否存在。

以下是亚马逊产品广告API的代码

<?php
error_reporting(0);

define('AWS_API_KEY', 'your key');
define('AWS_API_SECRET_KEY', 'your key');
define('AWS_ASSOCIATE_TAG', 'your tag');
define('AWS_ANOTHER_ASSOCIATE_TAG', '');

define('PRODUCT_NUMBER', 20);

  require('./lib/AmazonECS.class.php');


$category                   = $_REQUEST['category'];
$search                     = $_REQUEST['search'];
$page                       = (isset($_REQUEST['page']) && $_REQUEST['page'] != 0)?$_REQUEST['page']:1;

try
{
    $amazonEcs              = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'com', AWS_ASSOCIATE_TAG);

    $amazonEcs->associateTag(AWS_ASSOCIATE_TAG);
    $amazonEcs->returnType(AmazonECS::RETURN_TYPE_ARRAY);

    $response               = $amazonEcs->responseGroup('Large')->page(1)->category($category)->search($search);
    $page_count             = ceil(PRODUCT_NUMBER/10);
    $page_offset            = ($page-1)*$page_count+1;
    if($response['Items']['TotalPages'] <= $page_count){
         $page_count        = $response['Items']['TotalPages'];
    }
    $array_result           = array();
    for($i=$page_offset; $i<($page_count+$page_offset); $i++){
        $response_nxt       = $amazonEcs->responseGroup('Large')->page($i)->category($category)->search($search);
        $result_temp        = array_merge($array_result, $response_nxt['Items']["Item"]);
        $array_result       = $result_temp;
    }
    echo "<pre>";
    print_r($array_result);

}
catch(Exception $e)
{
  echo $e->getMessage();
}
?>