我正在尝试在 php 中使用亚马逊 api 代码,但它给了我不支持的版本的错误,以下是我的代码


I am trying to use amazon api code in php but it is giving me error of not supported version following is my code

以下是我与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 默认为已弃用的值。