Skip to main content

Use the Amazon API to Get Product Prices Easy Guide!

This tutorial helps you to learn how you can Use the Amazon API to Get Product Prices.

You can use the Amazon API to Get Product Prices, item description, customer reviews, product images, quantity available and other details of any product listed on various Amazon websites.

The region (such as “com” for the US or “es” for Spain) and 10-digit ASIN of any product are passed to the getAmazonPrice() method. The response is given back as JSON, which Google Scripts‘  Amazon Price Tracker can easily parse. However, you cannot use this method to retrieve Kindle Books prices as they are not yet supported by the Amazon API.

<?php

// Region code and Product ASIN
$response = getAmazonPrice("com", "B00KQPGRRE");

function getAmazonPrice($region, $asin) {

        $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);
        $code = htmlentities((string) $item->OfferSummary->LowestNewPrice->CurrencyCode);
        $qty = htmlentities((string) $item->OfferSummary->TotalNew);

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

        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;
}

function aws_signed_request($region, $params) {

        $public_key = "PUBLIC_KEY";
        $private_key = "PRIVATE_KEY";

        $method = "GET";
        $host = "ecs.amazonaws." . $region;
        $host = "webservices.amazon." . $region;
        $uri = "/onca/xml";

        $params["Service"] = "AWSECommerceService";
        $params["AssociateTag"] = "affiliate-20"; // Put your Affiliate Code here
        $params["AWSAccessKeyId"] = $public_key;
        $params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
        $params["Version"] = "2011-08-01";

        ksort($params);

        $canonicalized_query = array();
        foreach ($params as $param => $value) {
                $param = str_replace("%7E", "~", rawurlencode($param));
                $value = str_replace("%7E", "~", rawurlencode($value));
                $canonicalized_query[] = $param . "=" . $value;
        }

        $canonicalized_query = implode("&", $canonicalized_query);

        $string_to_sign = $method . "\n" . $host . "\n" . $uri . "\n" . $canonicalized_query;
        $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));
        $signature = str_replace("%7E", "~", rawurlencode($signature));

        $request = "http://" . $host . $uri . "?" . $canonicalized_query . "&Signature=" . $signature;
        $response = getPage($request);

        var_dump($response);

        $pxml = @simplexml_load_string($response);
        if ($pxml === False) {
                return False;// no xml
        } else {
                return $pxml;
        }
}

?>

Your public and private access keys must be obtained from the AWS Management Console and changed in the PHP code. For the country-specific Amazon Affiliate programme, you must also enter your Amazon Affiliate ID. For instance, even though you can use the same Access Keys with the code, the id for Amazon US and Amazon UK would differ.



from thetechxp https://ift.tt/W2Uf3d8
via IFTTT

Comments

Popular posts from this blog

किस महानगर में मिल रहा सबसे सस्ता पेट्रोल? जानें तेल का नया भाव https://ift.tt/zKAj5k6

रोज की तरह आज यानि 9 दिसंबर को भी तेल के नए रेट जारी कर दिए गए हैं. जिसके अनुसार, पेट्रोल-डीजल की कीमतों में कोई बदलाव नहीं किया गया है. सभी राज्यों में वाहन ईंधन की कीमतें जस की तस हैं. आइये जानते हैं, किस महानगर में सबसे कम कीमत पर पेट्रोल मिल रहा है और देश के किस इलाके में सबसे सस्ता और सबसे महंगा पेट्रोल मिल रहा है. from आज तक https://ift.tt/o9nAWyY via IFTTT

Best Website For Finding Government Jobs

  Online Sarkari Job Find   is a reliable and comprehensive online platform dedicated to providing the latest information on job opportunities. Our mission is to assist job seekers in finding their ideal positions by offering timely alerts and notifications on the latest job openings, Sarkari Results, Sarkari Exams, Sarkari jobs, Sarkari networks, and Sarkari Naukri. Our team of dedicated professionals is committed to keeping you informed about the most recent developments in the employment sector. With our user-friendly interface and up-to-date content, we strive to ensure that you have access to accurate and reliable information regarding various government job vacancies. Website Link -  Online Sarkari Job Find

IPL: कप्तान बाहर, दिग्गज भी निकले... रिटेंशन ने कैसे बदल दिया टीमों का गणित https://ift.tt/L7Adk8F

आईपीएल के अगले सीजन के लिए 23 दिसंबर को कोच्चि में मिनी ऑक्शन का आयोजन होना है. इस नीलामी से पहले सभी 10 टीमों की ओर से रिटेंशन लिस्ट जारी कर दी गई. from आज तक https://ift.tt/LK4D2kX via IFTTT