问题描述
我想使用App Script将Google Drive文件夹复制到另一个Google Drive.现在我正在将文件夹共享到目标帐户,并尝试将文件夹复制到目标google驱动器.这是我的应用脚本代码:
I want to copy google drive folder to another google Drive by using App Script. Right now I am sharing folder to target account and try to copy folder to target google drive.Here is my App Script Code:
// Make copy in Google Drive
function CopyTamplate(companyName) {
var folder = DriveApp.getFolderById("<<folder_id>>");
var folderid = folder.getId();
folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW);
Drive.Permissions.insert(
{
'role': 'reader',
'type': 'user',
'value': "[email protected]"
},
folderid,
{
'sendNotificationEmails': 'false'
});
var sourceFolder = "Company1_copy_tamplete";
var targetFolder = companyName;
var source = DriveApp.getFoldersByName(sourceFolder);
var target = DriveApp.createFolder(targetFolder);
if (source.hasNext()) {
copyFolder(source.next(), target);
}
}
这是通过目标电子邮件从一个驱动器到另一个驱动器的共享代码"文件夹,这是一个函数copyFolder:
This is a Code for Share folder from One Drive to another by Target Email, Here is a function copyFolder:
function copyFolder(source, target) {
var folders = source.getFolders();
var files = source.getFiles();
while(files.hasNext()) {
var file = files.next();
file.makeCopy(file.getName(), target);
}
while(folders.hasNext()) {
var subFolder = folders.next();
var folderName = subFolder.getName();
var targetFolder = target.createFolder(folderName);
copyFolder(subFolder, targetFolder);
}
}
我已经使用Google Script Execution API来调用此Script函数,但出现此错误. 脚本错误消息:"不允许操作".请帮助我解决问题或提出另一种执行此任务的方法.谢谢.
I have used Google Script Execution API for calling this Script function, and i am getting this Error. Script error message: "Action not allowed". Please help me to solve the issue or suggest another way to perform this task. Thank you.
推荐答案
之所以发生这种情况,是因为您在Drive.Permissions.insert中指定的角色是'role': 'reader'
.阅读共享文件文档,这些是读者":
This is happening because the role you specified in Drive.Permissions.insert is 'role': 'reader'
. Reading the Sharing Files docs, these are the only permitted operations for 'reader':
-读取文件的内容
-阅读文件夹中的项目列表
-Read the list of items in the folder
我建议将角色设置为所有者或作家.
I suggest setting the role to owner or writer instead.
这篇关于如何使用App Script将Google Drive文件夹复制到另一个Google Drive帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!