参数时间戳无效。原因:JavaScript 中必须为 ISO8601 格式
parameter Timestamp is invalid. Reason: Must be in ISO8601 format in JavaScript
我正在尝试拨打 Amazon RESTful API 的电话,但似乎是一个糟糕的开始或其他事情!
我收到这条消息:
<ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2013-08-01/">
<Error>
<Code>InvalidParameterValue</Code>
<Message>
Value 2015-3-24T18:38:26Z for parameter Timestamp is invalid. Reason: Must be in ISO8601 format.
</Message>
</Error>
<RequestId>77d4ca11-4f95-42d2-b85a-a4042abded80</RequestId>
</ItemLookupErrorResponse>
这是JavaScript中的代码:
var today = new Date();
var day = today.getDate();
var month = today.getMonth()+1;
var year = today.getFullYear();
var hours = today.getHours() < 10 ? "0"+today.getHours() : today.getHours();
var seconds = today.getSeconds() < 10 ? "0"+today.getSeconds() : today.getSeconds();
var mins = today.getMinutes() < 10 ? "0"+today.getMinutes() : today.getMinutes();
var time = encodeURIComponent(year+"-"+month+"-"+day+"T"+hours+":"+mins+":"+seconds+"Z");
var messageToEncrypt ="GET\nwebservices.amazon.com\n\
/onca/xml\nAWSAccessKeyId=ACCESSID&ItemId=0679722769&&SignatureMethod=HmacSHA256&SignatureVersion=2&Operation=ItemLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews&Service=AWSECommerceService&Timestamp="+time+"&Version=2013-08-01";
var sig = CryptoJS.HmacSHA256(messageToEncrypt, "SECRET KEY");
var request = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=AccessID&Operation=ItemLookup&ItemId=0976925524&ResponseGroup=SalesRank&Version=2013-08-01&Timestamp="+time+"&Signature="+sig;
function GET(url) {
var oFrame = document.getElementById("MyAjaxFrame");
if (!oFrame) {
oFrame = document.createElement("iframe");
oFrame.style.display = "none";
oFrame.id = "MyAjaxFrame";
document.body.appendChild(oFrame);
}
oFrame.src = url;
}
GET(request);
这里有什么问题吗?
谢谢
您可能缺少月份和日期的前导零。你的值应该大概是 2015-03-24T18:38:26Z
就像@Bergi 在评论中建议的那样-使用toISOString。
我正在尝试拨打 Amazon RESTful API 的电话,但似乎是一个糟糕的开始或其他事情!
我收到这条消息:
<ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2013-08-01/">
<Error>
<Code>InvalidParameterValue</Code>
<Message>
Value 2015-3-24T18:38:26Z for parameter Timestamp is invalid. Reason: Must be in ISO8601 format.
</Message>
</Error>
<RequestId>77d4ca11-4f95-42d2-b85a-a4042abded80</RequestId>
</ItemLookupErrorResponse>
这是JavaScript中的代码:
var today = new Date();
var day = today.getDate();
var month = today.getMonth()+1;
var year = today.getFullYear();
var hours = today.getHours() < 10 ? "0"+today.getHours() : today.getHours();
var seconds = today.getSeconds() < 10 ? "0"+today.getSeconds() : today.getSeconds();
var mins = today.getMinutes() < 10 ? "0"+today.getMinutes() : today.getMinutes();
var time = encodeURIComponent(year+"-"+month+"-"+day+"T"+hours+":"+mins+":"+seconds+"Z");
var messageToEncrypt ="GET\nwebservices.amazon.com\n\
/onca/xml\nAWSAccessKeyId=ACCESSID&ItemId=0679722769&&SignatureMethod=HmacSHA256&SignatureVersion=2&Operation=ItemLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews&Service=AWSECommerceService&Timestamp="+time+"&Version=2013-08-01";
var sig = CryptoJS.HmacSHA256(messageToEncrypt, "SECRET KEY");
var request = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=AccessID&Operation=ItemLookup&ItemId=0976925524&ResponseGroup=SalesRank&Version=2013-08-01&Timestamp="+time+"&Signature="+sig;
function GET(url) {
var oFrame = document.getElementById("MyAjaxFrame");
if (!oFrame) {
oFrame = document.createElement("iframe");
oFrame.style.display = "none";
oFrame.id = "MyAjaxFrame";
document.body.appendChild(oFrame);
}
oFrame.src = url;
}
GET(request);
这里有什么问题吗? 谢谢
您可能缺少月份和日期的前导零。你的值应该大概是 2015-03-24T18:38:26Z
就像@Bergi 在评论中建议的那样-使用toISOString。