0

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)
}
Jacob Ahlberg
  • 2,352
  • 6
  • 22
  • 44
  • Take a look at [this SO question](https://stackoverflow.com/questions/48293530/browse-files-in-google-team-drive) – Casper Nov 08 '18 at 08:20
  • Firstly, it different case i want to identify all team drive managers not only listing the files on team drive. Second, i have tested it before ask here, the problem is same since Drive API didnt have the authority to access all the team drive within the domain. – Rido Hermawan Nov 08 '18 at 09:03

1 Answers1

0

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.

Ruben Lopez
  • 704
  • 7
  • 18
  • At the first i already tried "Drive.Teamdrives.get" but i just dont know that "useDomainAdminAccess" can be used with that way :))) So i tested your solution and got no error but seems like i just cant get the owner or i mean the manager/organizer of the team drive since there are no field on teamdrive object. Is there any way to get this done? – Rido Hermawan Nov 08 '18 at 12:04
  • Yes, in that case you need to use [Permissions collection](https://developers.google.com/drive/api/v3/reference/permissions). You can call the function `Drive.Permissions.list(teamDrivesId, {useDomainAdminAccess : true, supportsTeamDrives:true})` and this will return a list of permissions granted on the Team Drive. There you can look for the organizers – Ruben Lopez Nov 08 '18 at 13:09