Amazon Product API with PHP + signature
Amazon api - aws using signature:
3 things to do : request for the keys, create the signature and get result from amazon.
1 Ask for your access key id + secret key.
2 how to create the signature:
[code]
$base_url = "http://ecs.amazonaws.com/onca/xml?";
$url_params = array('Operation'=>"ItemSearch",
'Service'=>"AWSECommerceService",
'AWSAccessKeyId'=>$AWS_ACCESS_KEY_ID,
'AssociateTag'=>"yourtag-10",
'Version'=>"2006-09-11",
'Operation'=>"ItemSearch",
'SearchIndex'=>"Music",
'ItemPage'=>"1"
,'ResponseGroup'=>"Images,ItemAttributes,EditorialReview",
'Keywords'=>"abba"
);
$url_params['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
// Sort the URL parameters
$url_parts = array();
foreach(array_keys($url_params) as $key)
$url_parts[] = $key."=".$url_params[$key];
sort($url_parts);
// Construct the string to sign
$string_to_sign = "GET\necs.amazonaws.com\n/onca/xml\n".implode("&",$url_parts);
$string_to_sign = str_replace(',','%2C',$string_to_sign);
$string_to_sign = str_replace(':','%3A',$string_to_sign);
$string_to_sign = str_replace(';',urlencode(';'),$string_to_sign);
// Sign the request
$signature = hash_hmac("sha256",$string_to_sign,$AWS_SECRET_ACCESS_KEY,TRUE);
// Base64 encode the signature and make it URL safe
$signature = base64_encode($signature);
$signature = str_replace('%7E','~',rawurlencode($signature));
[/code]
2 how to get date from Amazon:
$url_string = implode("&",$url_parts);
$url = $base_url.$url_string."&Signature=".$signature;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$xml_response = curl_exec($ch);
$curl_error = curl_error($ch);
if(empty($curl_error)){
if(!preg_match('/error 500/i',$xml_response)){
$result = simplexml_load_string($xml_response);
print_r($result);
}else{
echo "noe";
}
}else{
echo "not empty";
}
Source:
http://www.morganney.com/blog/API/AWS-Product-Advertising-API-Requires-a-Signed-Request.php
http://stackoverflow.com/questions/3234448/amazon-product-api-with-php
http://mierendo.com/software/aws_signed_query/
http://docs.amazonwebservices.com/AWSEcommerceService/2007-01-17/PgRestRequestsArticle.html