Get owner/manager of all the Team Drive within the domain (Google Apps Script)

I am newbie G-Suite domain administrator and I'm trying to fetch all of the team drives within the domain along with its owner. I used google apps script and success to grab all of the team drive name and id. But when I try to reach one of the team drive by its id DriveApp.getFolderById(teamDrivesId), I'm getting the following error:

Team Drive Not Found : {teamdriveid}.

Its well understood that i am not a member of those team drive, but I'm an admin so how can I get these things done? Please kindly help.

Here is the code :

function getTeamDriveName() {
    var teamDrivesName, teamDrivesId, pageToken;

    var ssDrives = SpreadsheetApp.openById(sheetTeamDrives.id);
    var sheetDrives = ssDrives.getSheetByName(sheetTeamDrives.sheet);

    do {
        var drivesList = Drive.Teamdrives.list({
            pageSize : 100,
            useDomainAdminAccess : true,
            pageToken: pageToken
        })

        var items = drivesList.items;                         
        for(var j = 0; j < items.length; j++) {
            teamDrivesName = items[j].name;
            teamDrivesId = items[j].id;

            var getDrive = DriveApp.getFolderById(teamDrivesId);
            sheetDrives.appendRow([teamDrivesId,teamDrivesName]);       
        }
        pageToken = drivesList.nextPageToken;
    }
    while (drivesList.nextPageToken)
}

1 answer

  • answered 2018-11-08 10:29 Rubén López

    First of all Team Drives are not folders, so you need to call another function in order to get Team Drives information from the API.

    Along with this, as you want to access to Team Drives as administrator, you need to use Teamdrives collection. So the function you need to call is Drive.Teamdrives.get(teamDrivesId, {useDomainAdminAccess : true}). There you will get information from those Teamdrives. *Source: https://developers.google.com/drive/api/v2/reference/teamdrives/get

    Anyways, you say you want to know the owners and I would like to remark that there aren't owners on Team Drives, that's exactly what make them different from your Drive.

    I hope it's clear and this could help you.