DriveApp.getFolderById权限 [英] DriveApp.getFolderById Permissions

查看:115
本文介绍了DriveApp.getFolderById权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将旧脚本从 DocsList 升级到 DriveApp ,并且遇到 getFolderById 调用的问题。该脚本以前使用过 DocsList.getFolder 。我有一个(以前创建的)名为电子邮件存档的文件夹,我试图在脚本中访问它。通过使用日志和执行脚本,我验证了我正确地将baseFolder参数中的字符串Email Archive传递给了以下语句:


var baseFolderObject = DriveApp.getFolderById(baseFolder);

执行该语句时,出现以下错误:


执行失败:找不到具有给定ID的项目,或者
没有权限访问它。 p>

电子邮件存档文件夹以前由脚本调用 docsList.CreateFolder 时由同一脚本创建,并没有指定权限。



我是否需要改变文件夹权限以允许我的脚本访问它,现在我正在使用 DriveApp 而不是<强>已超出DocsList ?我是否需要使用 DriveApp 创建新文件夹并指定权限,如果有,我设置了哪些权限以允许我的脚本访问文件夹并创建子文件夹和文件,而不允许其对文件夹可见整个互联网?



在此先感谢您的帮助,

〜Jim Fennell

$ b $在DriveApp中,您可以通过ID或名称获取文件夹。

您正在将该名称传递给getFolderById()方法。请尝试以下操作:

  var myFile = DriveApp.getFilesByName(baseFolder).next(); 

getFoldersByName返回一个具有迭代器携带的标准hasNext()/ next()语法的迭代器。上面的代码将使用'baseFolder'中提供的名称返回的第一个文件夹保存到myFile变量中。请记住,在驱动器中,多个文件夹可以具有相同的名称,因此可以将迭代器返回到单个文件夹。


I'm trying to "upgrade" an old script from DocsList to DriveApp and having a problem with a getFolderById call. The script had worked previously using DocsList.getFolder. I have a (previously-created) folder named "Email Archive" that I'm trying to access in script. Through using Logs and Execution Transcript, I've verified that I'm correctly passing the string "Email Archive" in the baseFolder parameter to the following statement:

var baseFolderObject = DriveApp.getFolderById(baseFolder);

When that statement is executed, I get the following error:

Execution failed: No item with the given ID could be found, or you do not have permission to access it.

The "Email Archive" folder was created previously by the same script with a script call to docsList.CreateFolder, and no permissions were specified.

Do I need to do something to change the folder permissions to allow my script to access it now that I'm using DriveApp instead of DocsList? Do I need to create a new folder using DriveApp and specify permissions, and if so what permissions do I set to allow my script to access the folder and create subfolders and files without allowing it to be visible to the entire Internet?

Thanks in advance for any help,

~ Jim Fennell

解决方案

In DriveApp you can get a folder by ID or by name. You are passing the name to the getFolderById() method. Try this below:

var myFile = DriveApp.getFilesByName(baseFolder).next();

The getFoldersByName returns an iterator that has the standard hasNext()/next() syntax that iterators carry. The code above saves the first folder returned with the name provided in 'baseFolder' to the myFile variable. Remember that in drive multiple folders can have the same name, hence returning an iterator vs a single folder.

这篇关于DriveApp.getFolderById权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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