如何将文件从MyDrive移到Team Drive?

时间:2018-11-14 14:25:29

标签: google-apps-script google-drive-team-drive

我想使用Google Apps脚本将文件从MyDrive传输到Team Drive。我可以手动执行此操作(因此我知道我有权限),并且启用了Drive API(因此能够保存到MyDrive)。但是,当我这样做时(这是我从另一篇文章中得到的):

function moveFileToFolder(fileId, newFolderId) {  
  var file = Drive.Files.get(fileId, {supportsTeamDrives: true});

  Drive.Files.patch(file, fileId, {
    supportsTeamDrives: true,
    corpora:            'teamDrive',
    removeParents:      file.parents.map(function(f) { return f.id; }),
    addParents:         [newFolderId],    
  });
}

我收到此错误:

Sharing restrictions cannot be set on a Team Drive item.

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

看来我在考虑以下方面:

var file = DriveApp.getFileById(fileId);
var parentFolder = DriveApp.getFolderById(TEAM_DRIVE_ID);
parentFolder.addFile(file);