起初,我在驱动器应用程序上运行它,它运行良好,然后尝试迁移到api,当我在使用HTML的UI中运行该程序时,我遇到了问题,但是程序无法运行,但是如果我运行通过选择功能并调试它可以在编辑器中使用相同的脚本,我相信问题是我必须使用api权限来做某事,因为当我将UI与HTML一起使用时,我正在Web浏览器上运行它,但是不知道该怎么办
我试图在google api控制台中创建一个项目,但是我也没有任何回应。
//html
function fillData() {
var folderId = document.getElementById("ingress").value;
document.getElementById("branch").innerHTML = "branch #" + (++branch);
google.script.run
.withSuccessHandler(newRun)
.withFailureHandler(error)
.fillData(folderId, 25,true);
}
//code.gs
function fillData(folderId, max, API) {
sheet = SpreadsheetApp.getActive().getActiveSheet();
var data = (API) ? API(folderId, max) :APP(folderId, max);
var lastRow= getLastRow_(hojaAuditoria.getRange("A4:A"), 4);
var dataRange = sheet.getRange(lastRow + 1, 1, data.length, data[0].length);
dataRange.setValues(data);
var timeStamp = new Date();
sheet.getRange("B3")
.setValue(timeStamp)
.setHorizontalAlignment('left')
.setFontWeight("normal")
.setNumberFormat('dd/MM/yyyy HH:mm');
SpreadsheetApp.flush();
return (PropertiesService.getUserProperties().getProperty("token") != null);
}
function API(folderId, max) {
max= (max === undefined) ? max= 100 : max;
var pageToken = PropertiesService.getUserProperties().getProperty("token");
var strAux = (folderId === undefined) ? "" : 'and "' + folderId + '" in parents';
var query = 'mimeType != "application/vnd.google-apps.folder"' + strAux;
var files;
var result = [];
files = Drive.Files.list({
q: query,
maxResults: max,
pageToken: pageToken,
includeRemoved: true,
spaces: 'drive'
});
if (files.items && files.items.length > 0) {
for (var i = 0; i < files.items.length; i++) {
var file = files.items[i];
var fileAux = DriveApp.getFileById(file.id);
SpreadsheetApp.getActiveSpreadsheet().toast(file.title, "audit");
var permissions = getPermissions(file.id);
var parents = getParentData(file.parents);
result[i] = [
file.id,
"=HYPERLINK(\"" + file.alternateLink + "\";\"" + file.title + "\")",
file.mimeType,
date(new Date(file.createdDate)),
date(new Date(file.modifiedDate)),
(file.fileSize === undefined) ? "" : file.fileSize,
parents[0],
parents[1],
parents[2],
(file.labels.trashed) ? "YES" : "NO",
fileAux.getSharingAccess(),
fileAux.getSharingPermission(),
permissions[0],
permissions[1],
permissions[2],
permissions[3]
];
}
} else {
Logger.log('No files found.');
}
pageToken = files.nextPageToken;
PropertiesService.getUserProperties().setProperty("token", pageToken);
return result;
}
我在fillData函数中使用API标志从driveApp更改为API,如果我通过Google脚本编辑器提供的调试运行它,但是我运行API时,我就可以完美地使用HTML的UI也可以在api中正常工作使用HTML的UI出现此错误
ReferenceError:未定义“驱动器”。在API(Permissions_Audit:26)在fillData(sheetAudit:62)