I'm using Google Apps Script and V2 of the Drive API (I don't think V3 is available in scripts yet) to automate file creation inside of a Team Drive. I'd like to add editors with the script with no success.
I can access the Team Drive and child folders using the FolderIterator
in the standard DriveApp
methods.
Attempt 1
function addUserToTeam(email, folders) {
// Open the team drive and get all the folders
var teamFolders = DriveApp.getFolderById('TEAMDRIVEIDSTRING').getFolders();
var folders = ["folderIdToMatch"] // This may hold multiple folders
try {
// Loop an array of folder IDs
for(var i=0; i<folders.length; i++) {
// Check the team drive folders for a matching name
while(teamFolders.hasNext()) {
var teamFolder = teamFolders.next();
if(folders[i] == teamFolder.getId()) {
teamFolder.addEditor(email);
}
}
}
} catch(e) {
Logger.log(e);
}
}
This failed with Exception: Cannot use this operation on a Team Drive item
.
Attempt 2
I tried the Drive API by substituting teamFolder.addEditor(email)
a Permissions
resource:
if(folders[i] == teamFolder.getId()) {
var resource = {
"type":"user",
"role":"writer",
"value": email
}
Drive.Permissions.insert(resource, teamFolder.getId());
}
This fails with a File not found
error.
I can find the folder (or file) with DriveApp
methods. Any attempt at the same with the Drive API fails.
I cannot find any documentation saying Team Drive files are inaccessible with the API. Is there something wrong with my approach?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…