Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I try to get prices of an ASIN number with the Amazon Product Advertising API.

Code:

    $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-dTH: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
ecs.amazonaws.de
/onca/xml
" . $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);

I think this should be correct - but I don't get offers in the 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>

Can someone please explain me why I don't get any price-information?

Thank you very much

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

To get prices for an item you need to include a ResponseGroup parameter of Offers or OfferFull and a MerchantId parameter of 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);

If you don't include the MerchantId of All you will only get offer listings for Amazon (the default MerchantId). This will return the offer listings and your response will include something like the following:

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

See the documentation for the Offers Response Group for more information. Also see the Response Group request parameter description for the ItemLookup operation for more valid Response Groups.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...