gpt4 book ai didi

google-apps-script - Google 脚本 - DriveApp.getFilesByName - 错误(无权限)

转载 作者:行者123 更新时间:2023-12-01 14:31:13 25 4
gpt4 key购买 nike

我正在尝试从 Google 电子表格调用自定义函数 pdfFile。

function pdfFile(number, revision) {
// Log the name of every file in the user's Drive.
Logger.log(number + '_R' + revision + '.pdf');

var files = DriveApp.getFilesByName(number + '_R' + revision + '.pdf');
while (files.hasNext()) {
var file = files.next();
//var name = file.getName();
var id = file.getId();
Logger.log(file.getName() + '|' + file.getId());

//Return link to PDF file
return '=HYPERLINK("https://docs.google.com/file/d/'+id+'/edit?usp=drivesdk";"PDF")';
}
}

当我在脚本编辑器中手动测试它时它有效。

function test_pdfFile() {
var range = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].getRange("D2:E2");

// Returns cell
var number = range.getCell(1, 1).getValue();
var revision = range.getCell(1, 2).getValue();

result = pdfFile(number, revision);
Logger.log(result);
}

但是,当我在电子表格中使用自定义公式时,出现错误“您无权调用函数 DriveApp.getFilesByName(第 5 行)”。我已经在 Resources->Additional Google Functions 和 Developer Console 中打开了 Drive API。请找到附加图片(抱歉,俄语文本)。请帮忙。

最佳答案

如果您的自定义函数抛出错误消息 You do not have permission to call X service.,则该服务需要用户授权,因此不能在自定义函数中使用。

检查这个documentation了解更多详情。

希望对您有所帮助!

关于google-apps-script - Google 脚本 - DriveApp.getFilesByName - 错误(无权限),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29860962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com