Reputation: 1625
We want to push copies of our school's materials to the students own "My Drive" folders.
The below script works well, and nicely puts a link of the source folder in the students "Shared with me" folder.
function setPermissions(){
var id = "SOURCE_FOLDER_ID"
var firstGet = DriveApp.getFolderById(id)
var folder = firstGet.getId()
Drive.Permissions.insert(
{
'role': 'writer',
'type': 'user',
'value': 'TARGET_USER_EMAIL',
},
folder,
{
'sendNotificationEmails': 'false'
});
}
However, these are young students about 8 or 9 years old and we want to the project folders we make to end up in their "My Drive" location without further click from the student's side.
I know we can use addFolder() to put the folders into the student's Google Drive root folder.
However, this means knowing the student's root folder ID.
Does anyone know how can I get the student's root folder IDs by iterating through their email addresses?
Google has documentation on how to get the current users rood folder, but I want to get the root folder ids of all the student's in the class.
Or am I approaching this in the wrong way?
Upvotes: 0
Views: 522
Reputation: 953
If you're inserting permissions -- Drive.Permissions.insert()
-- you're sharing the file, so the default location would be "Shared with me", so you'll need to move the file after you share it.
An alternative approach, which is what i think you want from your question, is to use Drive.Files.copy()
, which will put a copy if the item into a folder specified in the parents[]
property. Not setting the parents[]
array in the request body will set the destination to the account's Google Drive root.
Upvotes: 0