在删除一条评论时,我可以背靠背删除两条评论,但当我试图删除下一条评论(第三条评论)时。在控制台显示错误 "由于请求量过大,比率受限。" 但是过了几秒钟后,当我尝试删除时,接下来的两条评论都能正常工作。我曾尝试使用 "等待 "函数几秒钟使其工作,但结果不一致。我的代码如下。
function deleteComment(MessagePostId) {
var result = confirm("Are you sure you want to delete this Comment?");
if (result) {
yam.platform.request({
url: "https://api.yammer.com/api/v1/messages/" + MessagePostId,
method: "DELETE",
async: false,
beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', token) },
success: function (res) {
alert("The Comment has been deleted.");
//Code to remove item from array and display rest of the comment to screen
},
error: function (res) {
alert("Please try again after some time.");
}
})
}
}
你正在打 限额 防止来自普通用户的多个删除请求,比如您所点击的那些。API是为客户端应用设计的,在这些应用中,你也许会偶尔进行删除,但并不是大量删除。
为了处理速率限制,你需要更新你的代码来检查响应值在 res
变量。如果是HTTP 429响应,那么你被限制了速率,需要等待后再重试原始请求。