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

Par*_*ras 3 php amazon-s3 amazon-web-services

以下是我使用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."\"";

?>
Run Code Online (Sandbox Code Playgroud)

它给出错误作为不支持的版本我尝试了一切但仍然发生错误请帮助
响应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>
Run Code Online (Sandbox Code Playgroud)

fri*_*ght 9

在$ params数组中添加有效版本,例如:

"ResponseGroup" => "Images,ItemAttributes,Offers",
"Version" => "2015-10-01"
Run Code Online (Sandbox Code Playgroud)

我测试了你的脚本,发现它适用于上面的内容.

如果省略version参数,问题的原因似乎是API默认为不推荐使用的值.