亚马逊产品广告API PHP显示图像

时间:2012-12-19 20:48:03

标签: php amazon-ec2 amazon product

我很困惑如何在我的网站上显示产品图片。我编写了以下代码。如何从响应中提取产品图像?

    <?php


  require_once 'lib/AmazonECS.class.php';


 $client = new AmazonECS('AWSApi','AWSSected','DE','Assoicate');

 $response  = $client->category('Photo')->search('Nikon');

  var_dump($response);

   ?>

我得到以下回复(其中很多)。我删除了一些信息。

[8]=>
  object(stdClass)#71 (5) {
    ["ASIN"]=>
    string(10) "B008VO4INW"
    ["ParentASIN"]=>
    string(10) "B0091FA5PA"
    ["DetailPageURL"]=>
    string(217) "http://www.amazon.de/Nikon-Coolpix-L610-Kompaktkamera-Megapixel/dp/B008VO4INW%3FSubscriptionId%3XXX%26tag%3DXXXX%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB008VO4INW"
    ["ItemLinks"]=>
    object(stdClass)#72 (1) {
      ["ItemLink"]=>
      array(4) {
        [0]=>
        object(stdClass)#73 (2) {
          ["Description"]=>
          string(15) "Add To Wishlist"
          ["URL"]=>
          string(216) "http://www.amazon.de/gp/registry/wishlist/add-item.html%3Fasin.0%3DB008VO4INW%26SubscriptionId%3XXXQ%26tag%3DXXX%26linkCode%3Dsp1%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB008VO4INW"
        }
        [1]=>
        object(stdClass)#74 (2) {
          ["Description"]=>
          string(13) "Tell A Friend"
          ["URL"]=>
          string(181) "http://www.amazon.de/gp/pdp/taf/B008VO4INW%3FSubscriptionId%3XXXFQ%26tag%3DXXX0%26linkCode%3Dsp1%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB008VO4INW"
        }
        [2]=>
        object(stdClass)#75 (2) {
          ["Description"]=>
          string(20) "All Customer Reviews"
          ["URL"]=>
          string(185) "http://www.amazon.de/review/product/B008VO4INW%3FSubscriptionId%3DXXXTFQ%26tag%3DxXXX-20%26linkCode%3Dsp1%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB008VO4INW"
        }
        [3]=>
        object(stdClass)#76 (2) {
          ["Description"]=>
          string(10) "All Offers"
          ["URL"]=>
          string(187) "http://www.amazon.de/gp/offer-listing/B008VO4INW%3FSubscriptionId%3DXXXXQ%26tag%3DXXX0%26linkCode%3Dsp1%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB008VO4INW"
        }
      }
    }
    ["ItemAttributes"]=>
    object(stdClass)#77 (3) {
      ["Manufacturer"]=>
      string(5) "Nikon"
      ["ProductGroup"]=>
      string(11) "Photography"
      ["Title"]=>
      string(95) "Nikon Coolpix L610 Kompaktkamera (16 Megapixel, 14-fach opt. Zoom, 7,6 cm (3 Zoll) Display) rot"
    }
  }


 After incorporate changes below, got this response:

 object(stdClass)#85 (2) {
   ["OperationRequest"]=>
   object(stdClass)#86 (4) {
      ["HTTPHeaders"]=>
    object(stdClass)#87 (1) {
      ["Header"]=>
      object(stdClass)#88 (2) {
       ["Name"]=>
       string(9) "UserAgent"
        ["Value"]=>
        string(26) "PHP-SOAP/5.3.10-1ubuntu3.4"
      }
      }
    ["RequestId"]=>
    string(36) "2af6eed8-4c6e-4211-bdd6-48304336624d"
   ["Arguments"]=>
    object(stdClass)#89 (1) {
     ["Argument"]=>
      object(stdClass)#90 (2) {
        ["Name"]=>
        string(7) "Service"
       ["Value"]=>
        string(19) "AWSECommerceService"
     }
    }
    ["RequestProcessingTime"]=>
    float(0.00219)
   }
  ["Items"]=>
   object(stdClass)#91 (1) {
    ["Request"]=>
    object(stdClass)#92 (3) {
      ["IsValid"]=>
      string(5) "False"
      ["ItemLookupRequest"]=>
      object(stdClass)#93 (3) {
    ["IdType"]=>
    string(4) "ASIN"
    ["ResponseGroup"]=>
    string(6) "Images"
    ["VariationPage"]=>
    string(3) "All"
  }
  ["Errors"]=>
  object(stdClass)#94 (1) {
    ["Error"]=>
    object(stdClass)#95 (2) {
      ["Code"]=>
      string(21) "AWS.MissingParameters"
      ["Message"]=>
      string(80) "Your request is missing required parameters. Required parameters include ItemId."
    }
  }
}

}    }

1 个答案:

答案 0 :(得分:0)

search方法为您提供搜索结果,您需要多做一些才能获得图片。

  require_once 'lib/AmazonECS.class.php';
  $client = new AmazonECS('AWSApi','AWSSected','DE','Assoicate');
  $search  = $client->category('Photo')->search('Nikon');
  if ($search) {
    $lookup = $client->responseGroup('Images')->lookup($search->ASIN);
    echo '<pre>';
    var_dump($lookup); // will give you the item's object and the image's url
  }