学生成绩簿.由于“访问被拒绝:DriveApp",因此无法完成脚本; [英] Student Gradebook. Unable to complete script because of "Access denied: DriveApp"

查看:91
本文介绍了学生成绩簿.由于“访问被拒绝:DriveApp",因此无法完成脚本;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本从工作表"Studenti"中获取了35个学生姓名.然后找到名称正确的文件夹(即史密斯·彼得"),删除具有其名称的旧成绩的旧pdf文档(即史密斯·彼得.pdf"),然后将新制作的pdf保存到文件夹(史密斯·彼得")中具有新等级的文档('Smith Peter.pdf').然后从列表中选择另一个学生.

My script takes 35 student names from the Sheet 'Studenti'. Then finds the proper folder with their name (i.e. 'Smith Peter'), removes old pdf document with old grades holding their name (i.e 'Smith Peter.pdf') and saves to the folder ('Smith Peter') a newly made pdf document with new grades ('Smith Peter.pdf'). And goes to take another student from the list.

问题:在进行1,2或3次迭代后,脚本停止显示:访问被拒绝:DriveApp. (第22行,文件代码":files.next().setTrashed(true);).一个星期前,脚本运行正常,没有问题,我尝试在此处更改名称,文件夹,目标位置,源工作表并查看建议.但是没有成功.我不知道第22行出了什么问题,请帮助!

The problem: after 1,2 or 3 iterations the script stops saying: Access denied: DriveApp. (line 22, file "Code": files.next().setTrashed(true);). A week ago the script was working without problems, I tried to change names, folders, destinations, source sheets and checked advice here. But no success. I don't know what is wrong with the line 22. Please help!

代码已随附

执行记录(显示脚本已停止的地方)

Execution transcript (shows where the script has stopped)

function generatePdf() {

var report = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // Gradebook ready to save as pdf
var zasobnik = SpreadsheetApp.openById('1eygLDH0iJoXfcVOMIin0hnKpMF59HszmXZosPKvwYWc');  
var zasobsheet = zasobnik.getSheetByName("Studenti"); // list of 35 students with names, Folder IDs
var data = zasobsheet.getDataRange().getValues(); 
  
for (var i = 1; i < data.length; i++){
    report.getRange('B2').setValue(data[i][0]); // setting student's name in a gradebook (first column)
    report.getRange('B3').setValue(' '); // just to jump from B2 to B3
  
var pdf = DriveApp.getFileById('1WHwm7xK28Orj22RxaKWEsCl3UWvWxYUhRg4ZGf87-GQ'); // ID of Gradebook (IF of ActiveSpreadsheet)
var theBlob = pdf.getBlob().getAs('application/pdf').setName(data[i][0] + ".pdf");
var folder = DriveApp.getFolderById(data[i][2]); // third column
  
var files = DriveApp.getFilesByName(data[i][0] + ".pdf"); // pdf with old grades
      while (files.hasNext()) {    
       files.next().setTrashed(true);    
   }
var newFile = folder.createFile(theBlob); // creating pdf with new grades in the student's folder
 
 }
}

推荐答案

我在删除文件时遇到了同样的问题,这是我不拥有的. 我发现了

I have the same problem with trashing files, that I don't own. I found that

  1. 如果您在getEditors()或getViewers()列表中,则我有解决方案:只需撤消您自己的许可即可. file.revokePermissions(Session.getActiveUser());文件将消失.
  2. 如果文件设置了isShareableByEditors(),示例1将不起作用-如果它为"false",则您将无能为力.
  3. 如果您已将文件添加到驱动器中,并且每个人都可以通过链接公开访问该文件,则您将无法撤消权限,因为您没有该权限.应用脚本返回访问被拒绝.因此,我认为我可以setTrashed(true).我错了. Google还会返回访问被拒绝:DriveAp.

在通过应用程序脚本2和3的情况下,我找不到从驱动器中删除不需要的文件的方法.但是仍然可以通过单击它们并选择选项删除"来实现.

I didn't find a way to remove unwanted files from my drive in case 2 and 3 thru apps script. But it's still possible by clicking on them and choosing option "Remove".

这篇关于学生成绩簿.由于“访问被拒绝:DriveApp",因此无法完成脚本;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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