以下是我与 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>
最佳答案
将有效版本添加到您的 $params 数组,例如:
"ResponseGroup" => "Images,ItemAttributes,Offers",
"Version" => "2015-10-01"
我测试了您的脚本,发现它适用于上述内容。
问题的原因似乎是,如果您省略版本参数,API 默认为已弃用的值。
关于php - 我正在尝试在 php 中使用亚马逊 api 代码,但它给了我不支持版本的错误,以下是我的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35101317/