3

i have simple question because don´t find any answer for this. Actually i can use Amazon´s API for get informations about product from ASIN code, but in this image´s case, i can get one single image in different formats, big, middle thumb, etc, right ?

In my case i want know if it´s possible get all images from product, no only show 1 pic in different formats, if i can get all images using scraping, but in this case i want use API because it´s more clean and for haven´t problems with many queries from CURL using scraping

Actually i use this :

$gallery=htmlentities((string) $item->ImageSets->ImageSet->LargeImage->URL);

Item Structure :

$item = $xml->Items->Item;
$title = htmlentities((string) $item->ItemAttributes->Title);
$url = htmlentities((string) $item->DetailPageURL);
$image = htmlentities((string) $item->MediumImage->URL);
$price = htmlentities((string) $item->OfferSummary->LowestNewPrice->Amount);
$amount=htmlentities((string) $item->OfferSummary->LowestNewPrice->Amount);
$item->OfferSummary->LowestUsedPrice->Amount);
$code = htmlentities((string) $item->OfferSummary->LowestNewPrice->CurrencyCode);
$qty = htmlentities((string) $item->OfferSummary->TotalNew);
$gallery=htmlentities((string) $item->ImageSets->ImageSet->LargeImage->URL);

Function API Code :

function getAmazonPrice($region, $asin) 
{
global $precioamz;
global $amountamz;
global $imageamz;
global $galeriaamz;

$xml = aws_signed_request($region, array(
"Operation" => "ItemLookup",
"ItemId" => $asin,
"IncludeReviewsSummary" => False,
"ResponseGroup" => "Medium,OfferSummary",
));

$item = $xml->Items->Item;
$title = htmlentities((string) $item->ItemAttributes->Title);
$url = htmlentities((string) $item->DetailPageURL);
$image = htmlentities((string) $item->MediumImage->URL);
$price = htmlentities((string) $item->OfferSummary->LowestNewPrice->Amount);
$amount=htmlentities((string) $item->OfferSummary->LowestNewPrice->Amount);
 $item->OfferSummary->LowestUsedPrice->Amount);
$code = htmlentities((string) $item->OfferSummary->LowestNewPrice->CurrencyCode);
$qty = htmlentities((string) $item->OfferSummary->TotalNew);
$gallery=htmlentities((string) $item->ImageSets->ImageSet->LargeImage->URL);

/// $gallery=Images,ItemAttributes,Variations,VariationImages


if ($qty !== "0") 
{
$response = array(
"code" => $code,
"price" => number_format((float) ($price / 100), 2, '.', ''),
"image" => $image,
"url" => $url,
"title" => $title,
"amount" => $amount,
"galeria" => $gallery
);
}

$precioamz=$response['price'];
$amountamz=$response['amount'];
$imageamz=$response['image'];
$galeriaamz=$response['galeria'];

//return $response;
}

function getPage($url) 
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec($curl);
curl_close($curl);
return $html;
}

But only get 1 image and i want get all images from this product, thank´s for the help, regards

aynber
  • 22,380
  • 8
  • 50
  • 63
Jos
  • 29
  • 1
  • 5

2 Answers2

1

To fetch all the images you have to use, or add

Images,ItemAttributes,Variations,VariationImages as values for the request key ResponseGroup when you call aws_signed_request()

I'd expect of course a different response from the one you're getting now, so your response parsing code may need to be modified.

Inspect the response and edit your code accordingly.

Paolo
  • 15,233
  • 27
  • 70
  • 91
0

If I don't misunderstood your requirement, I assume your Amazon API XML respsnse is something like this that I took from Amazon API documentation page https://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_RetrievingImages.html. SO you can try this way to get all the image urls.

$xmlstr = <<<XML
<Item> 
  <ASIN>B004HO6I4M</ASIN> 
  <SmallImage> 
    <URL> 
      https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL75_.jpg 
    </URL> 
    <Height Units="pixels">75</Height> 
    <Width Units="pixels">56</Width> 
  </SmallImage> 
  <MediumImage> 
    <URL> 
      https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL160_.jpg 
    </URL> 
    <Height Units="pixels">160</Height> 
    <Width Units="pixels">120</Width> 
  </MediumImage> 
  <LargeImage> 
    <URL> 
      https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL500_.jpg 
    </URL> 
    <Height Units="pixels">500</Height> 
    <Width Units="pixels">375</Width> 
  </LargeImage> 
  <ImageSets> 
    <ImageSet Category="primary"> 
      <SwatchImage> 
        <URL>  
          https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL30_.jpg 
        </URL> 
        <Height Units="pixels">30</Height> 
        <Width Units="pixels">22</Width> 
      </SwatchImage> 
      <SmallImage> 
        <URL>  
          https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL75_.jpg 
        </URL> 
        <Height Units="pixels">75</Height> 
        <Width Units="pixels">56</Width> 
      </SmallImage> 
      <ThumbnailImage> 
        <URL>  
          https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL75_.jpg 
        </URL> 
        <Height Units="pixels">75</Height> 
        <Width Units="pixels">56</Width> 
      </ThumbnailImage> 
      <TinyImage> 
        <URL>  
          https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL110_.jpg 
        </URL> 
        <Height Units="pixels">110</Height> 
        <Width Units="pixels">82</Width> 
      </TinyImage> 
      <MediumImage> 
        <URL>  
          https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL160_.jpg 
        </URL> 
        <Height Units="pixels">160</Height> 
        <Width Units="pixels">120</Width> 
      </MediumImage> 
      <LargeImage> 
        <URL>  
          https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL500_.jpg 
        </URL> 
        <Height Units="pixels">500</Height> 
        <Width Units="pixels">375</Width> 
      </LargeImage> 
    </ImageSet> 
  </ImageSets>
</Item>
XML;

$images = new SimpleXMLElement($xmlstr);
$image_set = $images->ImageSets->ImageSet;
$all_images = [];
foreach($image_set->children() as $key=>$value){
    $all_images[$key] =trim((string)$value->URL);
}
print '<pre>';
print_r($all_images);
print '</pre>';

Output :

Array
(
    [SwatchImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL30_.jpg
    [SmallImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL75_.jpg
    [ThumbnailImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL75_.jpg
    [TinyImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL110_.jpg
    [MediumImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL160_.jpg
    [LargeImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL500_.jpg
)
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
  • No, in my question i speak about all images from product, if you go product in amazon you can see different images, from API only get 1 image with different sizes or resolutions, as you can put until here, but products have gallery of images, from API i want show all images of product not the same image, actually i can show all images using parser load DOM product when load website and show this images and store in db , but problem it´s that, from Amazon´s API only show me single image, the other images i don´t know if it´s possible show using only Amazon´s API – Jos Dec 30 '17 at 04:59