PHP Amazon Product advertising API tutorial
PHP Amazon Product advertising API tutorial
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
- Please Join Amazon Affiliate program and get your Associate Id
- Signup for Amazon Product advertising API
- Signup and get your AWSAccessKeyId and AWSSecretKey from Amazon Web service.
- Download amazon_api_class from codeigniter.
- 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.
- 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 !
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- Basic Authentication Process
- Search Index support by locale
- Amazon Associates Web Service Quick reference cards (pdf)
- To understand the Authentication process API scratchpad or a downloadable javascript page Signed request helper

- X
0 Hi,
Using your sample code I am getting this error "Invalid xml response."
Regards,
Partha - X
1 I think Amazon Product advertising API does not have a robust xml encoder and hence for certain "ResponseGroup" it does not encode the html properly in the returned xml.
I told before too that I removed all "verifyXmlResponse()" check from the amazon_api_class and parsed it separately.
Please removeelsehopefully that should work for you. Best of luck.
{
throw new Exception("Invalid xml response.");
} - X
0 Thanks for your reply.
I removed the exception line as you advice.
Now I got this error:
Could not connect to AmazonSales Rank :
ASIN :
I changed "com" to "in" in line 111 of amazon_api_class.api:
private function queryAmazon($parameters)
{
return aws_signed_request("in", $parameters, $this->public_key, $this->private_key, $this->associate_tag);
} - X
0 Hi
I wanted to know if we can implement the API in a way that we can display all the lightning deal products on our page. Anyone cracked it as of now, or know of how to do that?
Thanks
MAKE MONEY ONLINE PHP TUTORIAL

