如何将文件从MyDrive移到Team Drive? [英] How to move a file from MyDrive to Team Drive?

查看:134
本文介绍了如何将文件从MyDrive移到Team Drive?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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],    
  });
}

我收到此错误:

Sharing restrictions cannot be set on a Team Drive item.

有什么想法吗?

推荐答案

看来我在考虑以下方面:

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);

这篇关于如何将文件从MyDrive移到Team Drive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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