Hi, sorry for my bad English.
I would need to interface to the API of Amazon advertising product: http://docs.aws.amazon.com/AWSECommerceService/latest/DG/Welcome.html
These are the php and java codes provided by amazon to interface with API and get the url to be queried:
PHP version:
Java version:
Is there any library or class already developed that can help me? Thanks.
I would need to interface to the API of Amazon advertising product: http://docs.aws.amazon.com/AWSECommerceService/latest/DG/Welcome.html
These are the php and java codes provided by amazon to interface with API and get the url to be queried:
PHP version:
PHP:
<?php
// Your Access Key ID, as taken from the Your Account page
$access_key_id = "***";
// Your Secret Key corresponding to the above ID, as taken from the Your Account page
$secret_key = "***";
// The region you are interested in
$endpoint = "webservices.amazon.it";
$uri = "/onca/xml";
$params = array(
"Service" => "AWSECommerceService",
"Operation" => "ItemLookup",
"AWSAccessKeyId" => "***",
"AssociateTag" => "***",
"ItemId" => "B073SBZ8YH",
"IdType" => "ASIN",
"ResponseGroup" => "Images,ItemAttributes,Offers"
);
// Set current timestamp if not set
if (!isset($params["Timestamp"])) {
$params["Timestamp"] = gmdate('Y-m-d\TH:i:s\Z');
}
// Sort the parameters by key
ksort($params);
$pairs = array();
foreach ($params as $key => $value) {
array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
}
// Generate the canonical query
$canonical_query_string = join("&", $pairs);
// Generate the string to be signed
$string_to_sign = "GET\n".$endpoint."\n".$uri."\n".$canonical_query_string;
// Generate the signature required by the Product Advertising API
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $secret_key, true));
// Generate the signed URL
$request_url = 'http://'.$endpoint.$uri.'?'.$canonical_query_string.'&Signature='.rawurlencode($signature);
echo "Signed URL: \"".$request_url."\"";
?>
Java version:
B4X:
package com.amazon.advertising.api.sample;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
/*
* This class shows how to make a simple authenticated call to the
* Amazon Product Advertising API.
*
* See the README.html that came with this sample for instructions on
* configuring and running the sample.
*/
public class JavaCodeSnippet {
/*
* Your Access Key ID, as taken from the Your Account page.
*/
private static final String ACCESS_KEY_ID = "***";
/*
* Your Secret Key corresponding to the above ID, as taken from the
* Your Account page.
*/
private static final String SECRET_KEY = "***";
/*
* Use the end-point according to the region you are interested in.
*/
private static final String ENDPOINT = "webservices.amazon.it";
public static void main(String[] args) {
/*
* Set up the signed requests helper.
*/
SignedRequestsHelper helper;
try {
helper = SignedRequestsHelper.getInstance(ENDPOINT, ACCESS_KEY_ID, SECRET_KEY);
} catch (Exception e) {
e.printStackTrace();
return;
}
String requestUrl = null;
Map<String, String> params = new HashMap<String, String>();
params.put("Service", "AWSECommerceService");
params.put("Operation", "ItemLookup");
params.put("AWSAccessKeyId", "***");
params.put("AssociateTag", "***");
params.put("ItemId", "B073SBZ8YH");
params.put("IdType", "ASIN");
params.put("ResponseGroup", "Images,ItemAttributes,Offers");
requestUrl = helper.sign(params);
System.out.println("Signed URL: \"" + requestUrl + "\"");
}
}
Is there any library or class already developed that can help me? Thanks.