I am trying to change ownership of files in Google Drive, where my service account isn't owner of the file.
function getDriveFiles(folder, path) {
var folder = DriveApp.getFolderById("0B23heXhtbThYaWdxzMc");
var path = "";
var files = [];
var fileIt = folder.getFiles();
while ( fileIt.hasNext() ) {
var f = fileIt.next();
if (f.getOwner().getEmail() != "[email protected]")
files.push({owner: f.getOwner().getEmail(), id: f.getId()});
}
return files;
}
So my array looks like this:
var files = [
{[email protected], id=CjOqUeno3Yjd4VEFrYzg},
{[email protected], id=CjOqUYWxWaVpTQ2tKc3c},
{[email protected], id=CjOqUNTltdHo2NllkcWs},
{[email protected], id=CjOqUVTRRMnU2Y0ZJYms},
{[email protected], id=CjOqUXzBmeE1CT0VLNkE},
{[email protected], id=CjfKj4ur7YcttORkXTn8D2rvGE},
{[email protected], id=CjOqUY3RFUFlScDBlclk}
]
Next function that i need to pass this array to is batchPermissionChange which will batch change the ownership to my service account. However i would like it to run batchPermissionChange per user. So if e.g [email protected] have 4 files, i don't want the batchPermissionChange function to be triggered 4 times, i would like it to trigger it one time with [email protected], and include his four fileID's.
function batchPermissionChange(ownerEmail, filesArray){
Do batch job Google... https://www.googleapis.com/batch
}
Question
How do i run the function batchPermissionChange(ownerEmail, filesArray) with for e.g [email protected] with his 4 fileId's? I could loop through the array, like, 'for each item in array run batchPermissionChange', but that will trigger the batch-function 4 times for the user [email protected].