问题描述
我正在开发一个小应用程序,以便使用Google Appmaker在Google驱动器中移动文件.
Hi I am developing a little app to move files around google drive using google Appmaker.
我有可以选择文件和目标目录的代码.问题是调用服务器函数来运行DriveApp函数,如下所示:
I have the code working to select the file and the destination directory all fine. The problem is to call the server function to run DriveApp functions as follows:
function onClickbtnMove(widget, event){
var props = widget.root.properties;
fileids=props.FileIdList;
//fileids is a list object of fileIDs, in the following text i removed the loop and just try with one fileID
var i=0;
google.script.run
.withSuccessHandler (function (result) {
console.log (result);
})
.withFailureHandler (function (error) {
console.log (error);
})
.moveFiles_(fileids[i], props.FolderDestinationId);
}
服务器脚本为:
function moveFiles_(sourceFileId, targetFolderId) {
var file = DriveApp.getFileById(sourceFileId);
// file.getParents().next().removeFile(file); // removed until i get it working!!
DriveApp.getFolderById(targetFolderId).addFile(file);
return "1";
}
我确定确实有一些明显的东西,但是我得到了:
i am sure there is something totally obvious but i am getting:
google.script.run.withSuccessHandler(...)
.withFailureHandler(...).moveFiles_ is not a function`
任何指导都非常欢迎.预先感谢.
any guidance very welcome. thanks in advance.
推荐答案
问题取决于隐藏服务器脚本. 官方文档说:
因此,通过在函数名称后添加下划线,可以将其从客户端隐藏起来,因此会出现该错误.为了使用google.script.run
调用该函数,必须除去下划线,即,将函数moveFiles_(sourceFileId, targetFolderId)
更改为moveFiles(sourceFileId, targetFolderId)
.
So by appending an underscore to the function name, you are hiding it from the client, hence you are getting that error. In order to call the function using google.script.run
, you must get rid of the underscore, i.e., the function moveFiles_(sourceFileId, targetFolderId)
should be changed to moveFiles(sourceFileId, targetFolderId)
.
如果您感觉要向客户端公开敏感信息,那么在这种情况下,重要的是通过实现自己的方法来保护脚本.例如以下内容:
If you feel you are exposing sensitive information to the client, then in this case, it's important to secure your scripts by implementing your own method. Take for example the following:
function moveFiles(sourceFileId, targetFolderId, role) {
if(role === "Manager" || role === "Admin"){
var file = DriveApp.getFileById(sourceFileId);
DriveApp.getFolderById(targetFolderId).addFile(file);
return "1";
}
}
这篇关于google.script.run XX不是函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!