Amazon API получает все изображения из продукта

У меня простой вопрос, потому что я не могу найти ответ на этот вопрос. На самом деле я могу использовать API Amazon для получения информации о продукте из кода ASIN, но в этом случае я могу получить одно изображение в разных форматах, большой, средний и т. Д., Верно?

В моем случае я хочу знать, возможно ли получить все изображения из продукта, не только показывать 1 изображение в разных форматах, если я могу получить все изображения, используя scrapp, но в этом случае я хочу использовать API, потому что он более чистый и нет проблем со многими запросами из CURL с использованием scrapp

На самом деле я использую это:

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

Структура изделия:

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

Код API функции:

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,VariationImagesif ($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;
}

Но только получить 1 изображение, и я хочу получить все изображения из этого продукта, спасибо за помощь, с уважением

1

Решение

Если я не неправильно понял ваше требование, я предполагаю, что ваше XML API respsnse Amazon выглядит примерно так, как я взял на странице документации Amazon API. https://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_RetrievingImages.html. Таким образом, вы можете попробовать этот способ, чтобы получить все URL изображения.

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

Выход :

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
)
0

Другие решения

Чтобы получить все изображения, которые вы должны использовать, или добавить

Images,ItemAttributes,Variations,VariationImages в качестве значений для ключа запроса ResponseGroup когда ты звонишь aws_signed_request()

Конечно, я ожидаю, что ответ будет отличаться от того, который вы получаете сейчас, поэтому ваш код синтаксического анализа ответа может потребоваться изменить.

Проверьте ответ и отредактируйте свой код соответственно.

0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector