function itemLookup($itemID) { $query = array('Operation' => 'ItemLookup', 'ResponseGroup' => 'Small, Offers, Images', 'IdType' => 'ASIN', 'ItemId' => $itemID); $signed_url = sign_query($query); /* Use CURL to retrieve the data so that http errors can be examined */ $ch = curl_init($signed_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 7); $xml_string = curl_exec($ch); $curl_info = curl_getinfo($ch); if (curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); } curl_close($ch); if ($curl_info['http_code'] == 200) { // dump_xml($xml_string); $xml_obj = simplexml_load_string($xml_string, "SimpleXMLElement"); $xmlArray = json_decode(json_encode($xml_obj), true); } else { /* examine the $curl_info to discover why AWS returned an error $xml_string may still contain valid XML, and may include an informative error message */ echo json_encode($curl_info); } /* Traverse $xml_obj to display parts of it on your website */ if (!is_null($xml_obj)) { //error_reporting(0); //print_r($xmlArray); if (!is_null($xmlArray['Items']['Request']['IsValid']) && $xmlArray['Items']['Request']['IsValid'] == "True") { $name = $xmlArray['Items']['Item']['ItemAttributes']['Title']; $mediumImageURL = $xmlArray['Items']['Item']['MediumImage']['URL']; $rawValue = $xmlArray['Items']['Item']['OfferSummary']['LowestNewPrice']['Amount']; $formattedValue = $xmlArray['Items']['Item']['OfferSummary']['LowestNewPrice']['FormattedPrice']; echo $name . '<br>'; echo "<img src ='" . $mediumImageURL . "'> <br>"; echo $formattedValue; } } error_reporting(-1); exit; }
function scrap_apiprice($asin) { $response = sign_query('ASIN', $asin, 'Offers'); $listprice = simplexml_load_file($response); $prime = $listprice->Items->Item->Offers->Offer->OfferListing->IsEligibleForSuperSaverShipping; $price = 0; if ($prime == 1) { $amzprice = $listprice->Items->Item->Offers->Offer->OfferListing->SalePrice->FormattedPrice; if (isset($amzprice) && $amzprice != "") { $price = $amzprice; } else { $price = $listprice->Items->Item->Offers->Offer->OfferListing->Price->FormattedPrice; } } return $price; }