尝试删除文件时,拒绝访问驱动器应用程序 [英] Access denied Drive App when trying to delete file

查看:208
本文介绍了尝试删除文件时,拒绝访问驱动器应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个脚本,将我的谷歌驱动器中的所有 .xls .xlsx 文件转换为谷歌床单。但是,脚本的结果是非常不可靠的,有时我会在代码的某些随机部分中看到一个错误,并说:我们很抱歉,服务器发生了错误,请稍等一会儿再试一次。而其他时候,当我尝试删除转换后的 .xls .xlsx 时,出现Access denied Drive App code>文件。我为Drive API提供了Advance Google服务。

I wrote a little script to convert all the .xls and .xlsx files in my google drive to google sheets. However, the results of the script are very unreliable, sometimes I get an error, in some random part of the code, saying: "We're sorry, a server error occurred. Please wait a bit and try again.". And other times I get an error saying "Access denied Drive App" on the line where I try to delete my converted .xls or .xlsx files. I have enabled the Advance Google Services for the Drive API.

function convertFolder(folder){
  Logger.log('Folder name '+folder.getName());
  var files = folder.searchFiles('(title contains ".xlsx" or title contains ".xls") and (not title contains ".~lock")');
  while(files.hasNext()){
    var xFile = files.next();
    var name = xFile.getName().replace(/\.[^/.]+$/, "");
    Logger.log('File name '+name);
    if (name.indexOf(".~lock")!=-1)
      continue; //for some reason the "and (not title contains ".~lock")" didn't do the trick - why!?!
    var parents = xFile.getParents();
    var parents_arr = new Array();
    while (parents.hasNext()){
      parents_arr.push({'kind':"drive#fileLink",'id':parents.next().getId()});
    }

    var ID = xFile.getId();
    var xBlob = xFile.getBlob();
    var newFile = { title : name+'.gsheet',key : ID, parents: parents_arr, mimeType: "application/vnd.google-apps.spreadsheet"};
    file = Drive.Files.insert(newFile, xBlob, {convert: true});
    xFile.setTrashed(true);
  }
  var folders = folder.getFolders();
  while (folders.hasNext())
    convertFolder(folders.next());
}

function convertAllExcel(){
  var folders = DriveApp.getFoldersByName('Data');
  while (folders.hasNext()){
    var folder = folders.next();
    convertFolder(folder);
  }
  SpreadsheetApp.getUi().alert("done");
}


推荐答案

速率限制。如果您连续快速完成超过20个写入操作(创建,更新,删除),则需要将请求限制为大约每1.5秒一次。

I suspect you're hitting a rate limit. If you are doing more than 20 write operations (create, update, delete) in rapid succession, you need to throttle the requests to approximately one every 1.5 seconds.

可能会想到wtf,但这真的是您通过Drive获得的最大吞吐量。

You're probably thinking "wtf", but that's seriously the maximum throughput you can achieve with Drive.

这篇关于尝试删除文件时,拒绝访问驱动器应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆