以下是我使用php与amazon api服务获取xml响应的代码,但它给出了我在下面的代码中声明的错误。
<?php
// Your AWS Access Key ID, as taken from the AWS Your Account page
$aws_access_key_id = "A*********A";
// Your AWS Secret Key corresponding to the above ID, as taken from the AWS Your Account page
$aws_secret_key = "ue*******s+";
// The region you are interested in
$endpoint = "webservices.amazon.in";
$uri = "/onca/xml";
$params = array(
"Service" => "AWSECommerceService",
"Operation" => "ItemSearch",
"AWSAccessKeyId" => "AKIAJYSYWXDOF5CWIK5A",
"AssociateTag" => "unity0f-21",
"SearchIndex" => "All",
"Keywords" => "iphone",
"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, $aws_secret_key, true));
// Generate the signed URL
$request_url = 'http://'.$endpoint.$uri.'?'.$canonical_query_string.'&Signature='.rawurlencode($signature);
echo "Signed URL: \"".$request_url."\"";
?>
它提供错误作为不支持的版本我尝试了一切但仍然出现错误请帮助
对xml文件的请求的响应如下:
<?xml version="1.0"?>
<ItemSearchErrorResponse
xmlns="http://ecs.amazonaws.com/doc/2005-10-05/">
<Error>
<Code>UnsupportedVersion</Code>
<Message>Version 2005-10-05 is unsupported. Please use 2011-08-01 or greater instead.</Message>
</Error>
<RequestId>9f95a47d-f593-4002-af01-85b1b12fdf2d</RequestId>
</ItemSearchErrorResponse>
答案 0 :(得分:9)
在$ params数组中添加有效版本,例如:
"ResponseGroup" => "Images,ItemAttributes,Offers",
"Version" => "2015-10-01"
我测试了你的脚本,发现它适用于上面的内容。
问题的原因似乎是如果省略version参数,API默认为不推荐使用的值。