我正在使用这个在镀铬扩展中。
带有文件ID的简单请求将删除单个文件
xhr.open('DELETE', 'https://www.googleapis.com/drive/v2/files/' + ID, true);如果我想从Google删除多个文件,我会循环ID的数组并发送相同的请求,只是多次。
大多数请求都成功了,但是如果我有超过7-8的请求,其中一些请求会在error code 403中失败(我认为这是禁止的)。
通常,如果我有12个文件要删除,两个或三个将失败。
(当我重复请求时,它们将被删除)
Google是否有一些防止节流的保护措施,以及如何删除多个文件?
用计时器拖延(如)。( 100 ms)是不可取的,因为我可以删除数百个文件,处理它需要10-30秒。
REST驱动器API文档没有提到删除多个文件,只有一个文件
发布于 2017-06-16 20:57:43
这是使用REST从Google删除文件的批处理请求的示例代码:
var arrayOfFileIds; // array of id's of the files you want to delete
//notice that currently you can only batch up to 100 requests.
var authToken; //your OAuth2 token.
var xhr = new XMLHttpRequest;
var boundary = "END_OF_PART";
var separation = "\n--"+boundary + "\n";
var ending = "\n--" + boundary + "--";
var requestBody = arrayOfFileIds.reduce((accum,current)=>{
accum += separation +
"Content-Type: application/http\n\n" +
"DELETE https://www.googleapis.com/drive/v2/files/" +
current +
"\nAuthorization: Bearer " + authToken;
return accum;
},"") + ending;
xhr.onload = ()=>{
console.log(xhr.response);
//handle the response
};
xhr.open("POST", "https://www.googleapis.com/batch/drive/v2", true);
xhr.setRequestHeader("Content-Type","multipart/mixed; boundary=" + boundary);
xhr.send(requestBody);可选地,您可以向每个请求(在上面的content-id中)添加一个requestBody头,以标识批处理响应中的各个响应。
https://stackoverflow.com/questions/44142611
复制相似问题