Hi all,for setting the amazon product API you will need amazon associates account and AWS account. Create the account using this link: http://aws.amazon.com/. After registration, generate `AWS_API_KEY` & `AWS_API_SECRET_KEY`.
Download the API from:https://github.com/Exeu/apai-io. Use composer.phar to install the dependencies. After installing the dependencies a vendor folder will be created. In vendor folder you will need the path of autoload.php file. Where your autoload.php is located you can create config.php for amazon api configuration.
In your php file where you want the amazon api, initialize the api by including the autoload.php file .
In config.php put this code:
define('AWS_API_KEY', 'YOUR_API_KEY');
define('AWS_API_SECRET_KEY', 'YOUR_SECRET_KEY');
define('AWS_ASSOCIATE_TAG', 'ASSOCIATE_TAG');
define('AWS_ANOTHER_ASSOCIATE_TAG', 'ANOTHER ASSOCIATE TAG');
Include these file in your main file like this:
require_once "../../../../vendor/autoload.php";
require_once '../../../../vendor/Config.php';
Use API library like this:
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\ApaiIO;
use ApaiIO\Operations\Search;
use ApaiIO\Operations\Lookup;
Initialize the API Configuration:
$conf = new GenericConfiguration();
try {
$conf
->setCountry('com') //which amazon store you want to search(de, com, co.uk, ca, fr, co.jp, it, cn, es, in)
->setAccessKey(AWS_API_KEY)
->setSecretKey(AWS_API_SECRET_KEY)
->setAssociateTag(AWS_ASSOCIATE_TAG)
->setRequest('\ApaiIO\Request\Soap\Request')
->setResponseTransformer('\ApaiIO\ResponseTransformer\ObjectToArray');
} catch (\Exception $e) {
echo $e->getMessage();
}
Set up the search configuration like this. In '$category' you can pass following values:
(All','Apparel','Appliances','Automotive','Baby','Beauty','Blended','Books','Classical','DVD','Electronics','ForeignBooks','Grocery','HealthPersonalCare','HomeGarden','HomeImprovement','Jewelry','KindleStore','Kitchen','Lighting','Luggage','Marketplace','Magazines','MobileApps','MP3Downloads','Music','MusicalInstruments','MusicTracks','OfficeProducts','OutdoorLiving','Outlet','PCHardware','PetSupplies','Photo','Shoes','Software','SoftwareVideoGames','SportingGoods','Tools','Toys','VHS','Video','VideoGames','Watches' )
Pass your search value to '$search_item'. SetPage is for number of pages you want.
$search = new Search();
$search->setCategory($category); //Pass the category to $category
$search->setKeywords($search_item); //Pass the search value to $search_item
$search->setPage(5);
$search->setResponseGroup(array('Large')); //will return Item information in an multi-d array
$apaiIo = new ApaiIO($conf);
$response = $apaiIo->runOperation($search); //Amazon will return data in $response.
print_r($response);
setResponseGroup is for the information that is returned from amazon. setResponseGroup can have following values:
"Accessories,AlternateVersions,BrowseNodeInfoBrowseNodes,Cart,CartNewReleases,CartTopSellers,CartSimilarities,EditorialReview,Images,ItemAttributes,ItemIds,Large,Medium,MostGifted,MostWishedFor,NewReleases,OfferFull,OfferListings,Offers,OfferSummary,PromotionSummary,RelatedItems,Request,Reviews,SalesRank,SearchBins,Similarities,Small,TopSellers,Tracks,Variations,VariationImages,VariationMatrix,VariationOffers,VariationSummary "
For accessing the array use foreach loop.
3 Comment(s)