Exemple #1
0
/**
 * Given the title of a MediaWiki article, displays an ad
 * for DigitalMusic on Amazon, related to that title.
 */
function displayAdForTitle($title)
{
    global $LW_AMZN_OVERFLOW;
    $title = str_replace(":", " ", $title);
    $title = str_replace("_", " ", $title);
    ?>
<!doctype html>
<html lang="en" dir="ltr">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title><?php 
    print "{$title} on Amazon";
    ?>
</title>
		<style type='text/css'>
			html,body{margin:0;padding:0;background-color:#ddd;font-family:Helvetica;}
			img{border:0;}
			<?php 
    printCssByLayout();
    ?>
		</style>
	</head>
	<body>
		<div id='article'>
		<?php 
    $searchIndex = "DigitalMusic";
    $keywords = $title;
    ItemSearch($searchIndex, $keywords);
    ?>
		</div>
	</body>
</html><?php 
}
ini_set('display_errors', 1);
ini_set('log_errors', 1);
error_reporting(E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
//Enter your IDs
define("Access_Key_ID", "AKIAJA6JTHPOKRZ2GLZA");
define("Associate_tag", "giftertipster-20");
//Set up the operation in the request
function ItemSearch($SearchIndex, $Keywords)
{
    //Set the values for some of the parameters.
    $Operation = "ItemSearch";
    $Version = "2011-08-01";
    $ResponseGroup = "ItemAttributes,Offers";
    //$Signature = base64_encode(hash_hmac("sha256", $PrependString, $SecretAccessKey, True));
    //$Signature = str_replace("+", "%2B", $Signature);
    //$Signature = str_replace("=", "%3D", $Signature);
    //User interface provides values
    //for $SearchIndex and $Keywords
    //Define the request
    $request = "http://webservices.amazon.com/onca/xml" . "?Service=AWSECommerceService" . "&AssociateTag=" . Associate_tag . "&AWSAccessKeyId=" . Access_Key_ID . "&Operation=" . $Operation . "&Version=" . $Version . "&SearchIndex=" . $SearchIndex . "&Keywords=" . $Keywords . "&Signature=" . "" . "&ResponseGroup=" . $ResponseGroup;
    //Catch the response in the $response object
    //$response = file_get_contents($request);
    $response = file_get_contents('http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AKIAJA6JTHPOKRZ2GLZA&AssociateTag=giftertipster-20&Keywords=shoes&Operation=ItemSearch&SearchIndex=All&Service=AWSECommerceService&Timestamp=2012-03-24T21%3A34%3A44.000Z&Version=2011-08-01&Signature=OKwS80Dc%2FraWdFoYT9O3d%2FQjbgk66caGpVOkzRLNpNk%3D');
    $parsed_xml = simplexml_load_string($response);
    //printSearchResults($parsed_xml, $SearchIndex);
    echo '<pre>' . print_r($parsed_xml, true) . '</pre>';
}
ItemSearch($_GET['cats'], $_GET['keywords']);