问题
I would like to use Google Apps Script to transfer a file from MyDrive to Team Drive. I can do this manually (so I know I have permission) and I enabled the Drive API (so was able to save to MyDrive). However, when I do this (which I got from another post):
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],
});
}
I get this error:
Sharing restrictions cannot be set on a Team Drive item.
Any ideas?
回答1:
It appears I was overthinking it as the following works:
var file = DriveApp.getFileById(fileId);
var parentFolder = DriveApp.getFolderById(TEAM_DRIVE_ID);
parentFolder.addFile(file);
来源:https://stackoverflow.com/questions/53302468/how-to-move-a-file-from-mydrive-to-team-drive