PHP Amazon Product advertising API tutorial



6.73 K Views | Rishi Kashyap | 3
Rishi Kashyap
8.73 K
X

PHP Amazon Product advertising API tutorial


0

In this PHP tutorial about Amazon Product advertising API we will try to find offers on Amazon website using Amazon product API and also learn how to get required Amazon product details. I read documentation about Amazon Product advertising API but was still unable to use it, until I found Accessing Amazon Product Advertising API by Sameer Borate. So here are simple steps to use Amazon Product advertising API with PHP

  1. Please Join Amazon Affiliate program and get your Associate Id
  2. Signup for Amazon Product advertising API
  3. Signup and get your AWSAccessKeyId and AWSSecretKey from Amazon Web service.
  4. Download amazon_api_class from codeigniter.
  5. Unzip "AmazonAPI" and open "amazon_api_class.php" and edit $public_key (line 42), $private_key (line 49) and $associate_tag (line 57) with your AWSAccessKeyId, AWSSecretKey and Associate Id respectively.
  6. Place the folder in your server root or local host and open "Example.php" in your browser. You should be getting the result using Amazon Product advertising API now !
For me the Example worked perfectly but it was showing individual product details and so I tweaked a little, altered few things for Amazon India affiliate (com to in) and removed all "verifyXmlResponse()" check from the script as it was not showing returned Amazon data for certain "ResponseGroup".

My need was to find offers in Amazon affiliate to avoid common Affiliate marketing problems. The below code first tries to find offers on Amazon India website in Electronic section for keywords "Mobile Phones". Of course the keyword and some other details can come from text field in HTML Form. The final code in PHP<?php
include("amazon_api_class.php");

//valid parameters for $region are 'com','co.jp','fr','cn','in','de','co.uk','ca','es','it','com.br'

$region='in';
$category='ELECTRONICS';
$keyword='Mobile Phones';
$product_type='Electronics';
    $obj = new AmazonProductAPI();
    
    try
    {
        //$result = $obj->searchProducts("X-Men Origins",AmazonProductAPI::DVD,"TITLE");
        $result = $obj->getItemByKeyword($keyword,$product_type);
    }
    catch(Exception $e)
    {echo $e->getMessage();}

//print_r($result);exit;
//For each item returned
foreach($result->Items->Item as $tdata)
{
  //Get ASIN details
$asin=$tdata -> ASIN;
//Number of offers
$offercount=$tdata -> Offers ->MoreOffersUrl;
//If no offers continue;
if($offercount == '0'){continue;}
//If offers then get Item details by ASIN
$result1 = $obj->getItemByAsin($asin);
//print_r($result1);exit;
//For each item detail
foreach($result1->Items->Item as $tdata1)
{$pageurl=$tdata1 ->DetailPageURL;
$medimg=$tdata1 ->MediumImage->URL;
$title=$tdata1->ItemAttributes->Title;
$features=$tdata1 ->ItemAttributes->Feature[0];
$features .=$tdata1 ->ItemAttributes->Feature[1];
$features .=$tdata1 ->ItemAttributes->Feature[3];
$retailprice=$tdata1->ItemAttributes->ListPrice->FormattedPrice;
$saleprice=$tdata1->OfferSummary->LowestNewPrice->FormattedPrice;
//Show the details about product and offer
echo "<br/><a href='$pageurl'><img src='$medimg'/><br/>
<b>$title</b><br/>
$features<br/>
$retailprice<br/>
$saleprice
</a><br/>";
}
}
?>
For details, please refer
  1. Basic Authentication Process
  2. Search Index support by locale
  3. Amazon Associates Web Service Quick reference cards (pdf)
  4. To understand the Authentication process API scratchpad or a downloadable javascript page Signed request helper
I highly recommend to play around with Amazon Product advertising API and "Response group" for better understanding of Amazon product API. Best of luck.PHP Amazon Product advertising API tutorial

Rishi Kashyap | | EDIT | REPLY


tags  MAKE MONEY ONLINE PHP TUTORIAL

SUBSCRIBE TO RISHI'S BLOGS

SHARE Whatsapp Facebook Twitter To TOP