Kode Generate Amazon

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

<?

php
function Get_Amazon_XML($tag, $api, $secretkey, $region, $department, $query){
$time = time() + 10000;
$method = 'GET';
$host = 'webservices.amazon.'.$region;
$uri = '/onca/xml';
$slug["Service"] = "AWSECommerceService";
$slug["Operation"] = "ItemSearch";
$slug["SubscriptionId"] = $api;
$slug["AssociateTag"] = $tag;
$slug["SearchIndex"] = $department;
$slug["Condition"] = 'All';
$slug["Keywords"] = $query;
$slug["ItemPage"] = 1;
$slug["TruncateReviewsAt"] = '500';
$slug["ResponseGroup"] = 'Images,ItemAttributes,EditorialReview';
$slug["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z",$time);
$slug["Version"] = "2011-08-01";
ksort($slug);
$query_slug = array();
foreach ($slug as $slugs=>$value){
$slugs = str_replace("%7E", "~", rawurlencode($slugs));
$value = str_replace("%7E", "~", rawurlencode($value));
$query_slug[] = $slugs."=".$value;
}
$query_slug = implode("&", $query_slug);
$signinurl = $method."\n".$host."\n".$uri."\n".$query_slug;
$signature = base64_encode(hash_hmac("sha256", $signinurl, $secretkey, True)); /
/ Get Amazon Signature API
$signature = str_replace("%7E", "~", rawurlencode($signature));
$request = "http://".$host.$uri."?".$query_slug."&Signature=".$signature;
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Konqueror/4.0; Mic
rosoft Windows) KHTML/4.0.80 (like Gecko)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
curl_close($ch);return $response;
}
?>
Nah paste aja kode tersebut di functions.php di theme-files agan2 semua..berikut
nya untuk memanggilnya caranya seperti ini:
sebagai contoh, ini adalah untuk department Books karena biasanya tiap departmen
t ada yang beda:
<?php
$tag = 'YOUR_AFF_ID'; // ganti dengan kode affiliasi agan
$api = 'YOUR_API_KEY'; // ganti dengan api key amazon agan
$secretkey = 'YOUR_SECRET_KEY'; // ganti dengan secret key amazon agan
$region = 'com'; // Choose Region Based on Amazon Domain Extension$query = get_s
earch_query(); // This to get keywords you can sets as you want$department = 'Bo
oks'; // Choose Department you want to grab
$agc = Get_Amazon_XML($tag, $api, $secretkey, $region, $department, $query);
if(@simplexml_load_string($agc)){
$xmlin = simplexml_load_string($agc);
if(!empty($xmlin)){
$Total = $xmlin->Items->TotalResults; // to show result total

$xmls = $xmlin->Items->Item;
foreach($xmls as $xml){
$AmaTitle = $xml->ItemAttributes->Title; // Title
$AmaThumb = $xml->MediumImage->URL; // Medium Thumbnail
$AmaAsin = $xml->ASIN; // ASIN
$AmaLink = $xml->DetailPageURL; // link complete with your aff ID
$AmaStock = $xml->ItemAttributes->NumberOfItems; // Products Stocks
$AmaBind = $xml->ItemAttributes->Binding; // Bind
$AmaBrand = $xml->ItemAttributes->Brand; // Brand
$AmaDept = $xml->ItemAttributes->Department; // Department
$AmaEAN = $xml->ItemAttributes->EAN;
$AmaListPrice = $xml->ItemAttributes->ListPrice->FormattedPrice; // Price
$AmaCurrency = $xml->ItemAttributes->ListPrice->CurrencyCode; // Currency
$AmaDescription = $xml->EditorialReviews->EditorialReview->Content; // Product D
escription
echo '<h2>'.$AmaTitle.'</h2>' . "\n";
echo '<div>' . "\n";
echo '<img src="'.$AmaThumb.'" data-src="'.$AmaThumb.'" width="'.$xml->MediumIma
ge->Width.'" height="'.$xml->MediumImage->Height.'" alt="'.$AmaTitle.'" />' . "\
n";
echo '</div>' . "\n";
echo '<div>' . "\n";
echo '<p>Price: '.$AmaListPrice.'</p>' . "\n";
echo '<p>Currency: '.$AmaCurrency.'</p>' . "\n";
echo '<p>Department: '.$AmaDept.'</p>' . "\n";
echo '<p>Brand: '.$AmaBrand.'</p>' . "\n";
echo '<p><a title="'.$AmaTitle.'" href="'.$AmaLink.'" rel="nofollow" target="_bl
ank">Buy Now</a></p>' . "\n";
echo '</div><div></div>' . "\n";
echo '<ol>' . "\n";
foreach($xml->ItemAttributes->Feature as $feature){
echo '<li>'.$feature.'</li>' . "\n";
}
echo '</ol>' . "\n";
echo $AmaDescription.'' . "\n";
}
}
}
?>
klo untuk category ato department lain agan bisa lihat dulu xml schemenya dengan
cara:
<?php
$tag = 'YOUR_AFF_ID'; // ganti dengan kode affiliasi agan
$api = 'YOUR_API_KEY'; // ganti dengan api key amazon agan
$secretkey = 'YOUR_SECRET_KEY'; // ganti dengan secret key amazon agan
$region = 'com'; // Choose Region Based on Amazon Domain Extension
$query = get_search_query(); // This to get keywords you can sets as you want
$department = 'Books'; // Choose Department you want to grab
$agc = Get_Amazon_XML($tag, $api, $secretkey, $region, $department, $query);
if(@simplexml_load_string($agc))
{
$xmlin = simplexml_load_string($agc);
if(!empty($xmlin))
{
print_r($xmlin);
}
}

?>

You might also like