php 我无法通过Amazon产品广告API获取价格

ut6juiuv  于 2023-02-18  发布在  PHP
关注(0)|答案(7)|浏览(173)

我尝试用亚马逊产品广告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>

为什么我得不到任何价格信息?

aij0ehis

aij0ehis1#

要获取项目的价格,您需要包括OffersOfferFullResponseGroup参数和AllMerchantId参数:

$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);

如果您不包含AllMerchantId,您将只能获得Amazon的优惠列表(默认为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的响应组请求参数说明。

huwehgph

huwehgph2#

我建议您使用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" 
            }

...

myzjeezk

myzjeezk3#

使用“medium”作为“ResponseGroup”参数,允许值为small、medium和large。small响应将不包含价格详细信息。
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/RG_Small.html

8dtrkrch

8dtrkrch4#

Xarem,请看一下Product Advertising API(API参考/操作)。您请求了ItemLookup操作,但没有为您承诺价格。使用SellerListingLookup(或其他一些)操作来获取可用价格。这是完全可以理解的,因为亚马逊有一个很大的卖家池,每个卖家的价格都不相同,所以他们不能提供商品的价格,而是提供商品-卖家对的价格。

dojqjjoe

dojqjjoe5#

如果我有足够的代表,我会对早期的解决方案发表评论,但唉,我只能提供一个新的答案...
因此,如果您传递的MerchantId值为All,您将在响应中看到以下内容:

<MerchantId>Deprecated</MerchantId>

这向我表明,也许您不应该提供这个参数,这与所选答案所建议的相反。
不仅如此,我怀疑还有其他事情发生。我可能会在这里提出一个全新的问题,但我提交了一个具有有效ASIN的产品请求,返回True,请求响应组Offers、OfferFull和OfferSummary,但我没有返回任何价格信息。然而,当我在www.example.com上查看同一产品时amazom.com,我看到了价格信息。
所以可能还有别的地方出了问题。

xggvc2p6

xggvc2p66#

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

unguejic

unguejic7#

编辑您的响应组,如下所示:responseGroup('中,优惠摘要,变更摘要')
在响应组中,您将获得关键字“VariationSummary”,在此对象中,您可以检查价格的以下参数:

  • 最低价格
  • 最高价
  • 最低售价
  • 最高销售价格

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

相关问题