我没有通过亚马逊产品广告API获得价格

时间:2011-11-29 01:34:23

标签: php amazon amazon-product-api

我尝试使用亚马逊产品广告API获取ASIN号码的价格。

代码:

    $artNr = "B003TKSD8E";
    $base_url = "http://ecs.amazonaws.de/onca/xml";
    $params = array(
        'AWSAccessKeyId' => self::API_KEY,
        'AssociateTag' => self::API_ASSOCIATE_TAG,
        'Version' => "2010-11-01",
        'Operation' => "ItemLookup",
        'Service' => "AWSECommerceService",
        'Condition' => "All",
        'IdType' => 'ASIN',
        'ItemId' => $artNr);


    $params['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());

    $url_parts = array();
    foreach(array_keys($params) as $key)
        $url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));
    sort($url_parts);

    $url_string = implode("&", $url_parts);
    $string_to_sign = "GET\necs.amazonaws.de\n/onca/xml\n" . $url_string;

    $signature = hash_hmac("sha256", $string_to_sign, self::API_SECRET, TRUE);

    $signature = urlencode(base64_encode($signature));

    $url = $base_url . '?' . $url_string . "&Signature=" . $signature;

    $response = file_get_contents($url);
    $parsed_xml = simplexml_load_string($response);

我认为这应该是正确的 - 但我没有在回复中得到报价:

<?xml version="1.0" ?>
  <ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2010-11-01">
    <OperationRequest>
      <RequestId>*********************</RequestId>
      <Arguments>
        <Argument Name="Condition" Value="All">
      </Argument>
        <Argument Name="Operation" Value="ItemLookup">
      </Argument>
        <Argument Name="Service" Value="AWSECommerceService">
      </Argument>
        <Argument Name="ItemId" Value="B003TKSD8E">
      </Argument>
        <Argument Name="IdType" Value="ASIN">
      </Argument>
        <Argument Name="AWSAccessKeyId" Value="*********************">
      </Argument>
        <Argument Name="Timestamp" Value="2011-11-29T01:49:01.000Z">
      </Argument>
        <Argument Name="Signature" Value="*********************">
      </Argument>
        <Argument Name="AssociateTag" Value="*********************">
      </Argument>
        <Argument Name="Version" Value="2010-11-01">
      </Argument>
    </Arguments>
      <RequestProcessingTime>0.0083130000000000</RequestProcessingTime>
    </OperationRequest>
    <Items>
      <Request>
        <IsValid>True</IsValid>
        <ItemLookupRequest>
          <Condition>All</Condition>
          <IdType>ASIN</IdType>
          <ItemId>B003TKSD8E</ItemId>
          <ResponseGroup>Small</ResponseGroup>
          <VariationPage>All</VariationPage>
        </ItemLookupRequest>
      </Request>
      <Item>
        <ASIN>B003TKSD8E</ASIN>
        <DetailPageURL>http://www.amazon.de/Apple-iPhone-4-32GB-schwarz/dp/B003TKSD8E%3FSubscriptionId%3DAKIAI6NFQHK2DQIPRUEQ%26tag%3Dbanholzerme-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB003TKSD8E</DetailPageURL>
        <ItemLinks>
          <ItemLink>
            <Description>Add To Wishlist</Description>
            <URL>http://www.amazon.de/gp/registry/wishlist/add-item.html%3Fasin.0%3DB003TKSD8E%26SubscriptionId%3DAKIAI6NFQHK2DQIPRUEQ%26tag%3Dbanholzerme-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB003TKSD8E</URL>
          </ItemLink>
          <ItemLink>
            <Description>Tell A Friend</Description>
            <URL>http://www.amazon.de/gp/pdp/taf/B003TKSD8E%3FSubscriptionId%3DAKIAI6NFQHK2DQIPRUEQ%26tag%3Dbanholzerme-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB003TKSD8E</URL>
          </ItemLink>
          <ItemLink>
            <Description>All Customer Reviews</Description>
            <URL>http://www.amazon.de/review/product/B003TKSD8E%3FSubscriptionId%3DAKIAI6NFQHK2DQIPRUEQ%26tag%3Dbanholzerme-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB003TKSD8E</URL>
          </ItemLink>
          <ItemLink>
            <Description>All Offers</Description>
            <URL>http://www.amazon.de/gp/offer-listing/B003TKSD8E%3FSubscriptionId%3DAKIAI6NFQHK2DQIPRUEQ%26tag%3Dbanholzerme-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB003TKSD8E</URL>
          </ItemLink>
        </ItemLinks>
        <ItemAttributes>
          <Manufacturer>Apple Computer</Manufacturer>
          <ProductGroup>CE</ProductGroup>
          <Title>Apple iPhone 4 32GB schwarz</Title>/ItemAttributes>
        </Item>
      </Items>
    </ItemLookupResponse>

有人可以解释一下为什么我没有得到任何价格信息吗?

非常感谢

7 个答案:

答案 0 :(得分:22)

要获取商品的价格,您需要添加ResponseGroup参数OffersOfferFull以及MerchantId All参数:

$params = array(
    'AWSAccessKeyId' => self::API_KEY,
    'AssociateTag' => self::API_ASSOCIATE_TAG,
    'Version' => "2010-11-01",
    'Operation' => "ItemLookup",
    'Service' => "AWSECommerceService",
    'Condition' => "All",
    'IdType' => 'ASIN',
    'ResponseGroup' => 'Offers',                <- important
    'MerchantId' => 'All',                      <- important
    'ItemId' => $artNr);

如果您不包含MerchantId All,则只会获得亚马逊的优惠信息(默认MerchantId)。这将返回商品详情,您的回复将包含以下内容:

<Items>
    ...
    <Item>
        ...
        <Offers>
            ...
            <Offer>
                ...
                <OfferListing>
                    <Price>
                        <Amount>1350</Amount>
                        <CurrencyCode>USD</CurrencyCode>
                        <FormattedPrice>$13.50</FormattedPrice>
                    </Price>
                    ...
                </OfferListing>
                ...
            </Offer>
       ...

有关详细信息,请参阅Offers Response Group的文档。另请参阅ItemLookup operation的响应组请求参数说明,以获取更多有效的响应组。

答案 1 :(得分:3)

我建议您使用OfferSummary响应组,它将返回如下内容: ...

["Items"]=> object(stdClass)#72 (2) { 
    ... 
    ["Item"]=> object(stdClass)#75 (2) {
        ["ASIN"]=> string(10) "1405910232" 
        ["OfferSummary"]=> object(stdClass)#76 (6) { 
            ["LowestNewPrice"]=> object(stdClass)#77 (3) {  
                ["Amount"]=> int(247) 
                ["CurrencyCode"]=> string(3) "GBP" 
                ["FormattedPrice"]=> string(6) "£2.47" 
            } 
            ["LowestUsedPrice"]=> object(stdClass)#78 (3) {
                ["Amount"]=> int(297) 
                ["CurrencyCode"]=> string(3) "GBP" 
                ["FormattedPrice"]=> string(6) "£2.97" 
            }

...

答案 2 :(得分:3)

对“ResponseGroup”参数使用“medium”,允许值为small,medium和large。小的回复不会有价格细节。

http://docs.aws.amazon.com/AWSECommerceService/latest/DG/RG_Small.html

答案 3 :(得分:2)

Xarem,请看一下Product Advertising API(API参考/操作)。您已经请求了ItemLookup操作,并且没有为您承诺价格。使用SellerListingLookup(或其他一些)操作来获取可用价格。这是可以理解的,因为亚马逊有很多卖家,价格也各不相同,所以他们不能提供物品的价格,而是物品 - 卖家对。

答案 4 :(得分:2)

如果我有足够的代表,我会对早期的解决方案发表评论,但是我只能提供一个新答案......

因此,如果您将MerchantId值传递给All,您会在回复中看到这一点:

<MerchantId>Deprecated</MerchantId>

这向我表明,或许你不应该提供这个参数,与所选答案的建议相反。

不仅如此,我怀疑还有其他事情发生。我可能会在这里提出一个全新的问题,但是我提交了一个有效ASIN产品的请求,返回True,请求响应组Offers,OfferFull和OfferSummary,我没有回复任何价格信息。然而,当我在amazom.com上查看相同的产品时,我看到了价格信息。

这里还有别的东西可能是错的。

答案 5 :(得分:0)

您可以使用associate script中的解析器来回答您的问题。

答案 6 :(得分:0)

编辑您的回复组,如下所示: responseGroup(&#39;中,OfferSummary,VariationSummary&#39)

在回复组中,您将获得密钥&#34; VariationSummary&#34;在这个对象中你可以查看下面的参数价格:

  • LowestPrice
  • HighestPrice
  • LowestSalePrice
  • HighestSalePrice

请注意,您可能无法在VariationSummary对象中获得4个以上的所有参数。