google-apps-scriptgoogle-drive-api

How are list the permissions of shared drive in app-script


I'm trying list the permissions of shared drive but several items are undefined

function listAllSharedDrives() {
  let pageToken = null;
  let page;
  let pageperm;
  let contador=0;
  let idunidad;

  Logger.clear();
  //do {
    page = Drive.Drives.list({
      pageSize: 1,
      pageToken: pageToken,
      q: 'memberCount = 1',
      //fields isn't documented in Drive API v3, but is necessary to evoid undefined fields.
      fields: 'nextPageToken, drives(id, name, createdTime)',
      useDomainAdminAccess: true
    });
    const drives = page.drives;
    if (drives) 
    // Print the drive's name.
      for (const drive of drives) {
        contador+=1;
        console.log('Id: %s Nombre: %s Creado en: %s', drive.id, drive.name, drive.createdTime);
        
        pageperm = Drive.Permissions.list (drive.id,{
          supportsAllDrives: true,
          useDomainAdminAccess: true
        })
        const lospermisos = pageperm.permissions;
        if (lospermisos)
         for (const mipermiso of lospermisos) {
           console.log('Permiso ID: %s\nDisplayName: %s\nTipo: %s\nKind: %s\nRole: %s\nEmail: %s\nDominio: %s\nExpirationTime: %s\nDeleted: %s\nView: %s\nPendingOwner: %s',mipermiso.id,mipermiso.displayName,mipermiso.type,mipermiso.kind,mipermiso.role,mipermiso.emailAddress,mipermiso.domain,mipermiso.expirationTime,mipermiso.deleted,mipermiso.view,mipermiso.pendingOwner);
           if (mipermiso.PermissionDetails)
             for (const detalle of mipermiso.PermissionDetails) {
               console.log('Detalle permissionType: %s inheritedFrom: %s Role: %s Inherited: %s',detalle.PermissionType,detalle.inheritedFrom,detalle.role,detalle.inherited)
             }
         }
        console.log('');
      }
  //  pageToken = page.nextPageToken;
  //} while (pageToken);
  console.log('Total de unidades compartidas %d',contador);  
}

OUTPUT: Información Id: 0APeuZG... Nombre: UAL Creado en: 2024-01-15T10:33:37.635Z Información Permiso ID: 156621468... DisplayName: undefined Tipo: user Kind: drive#permission Role: organizer Email: undefined Dominio: undefined ExpirationTime: undefined Deleted: undefined View: undefined PendingOwner: undefined


Solution

  • Although I'm not sure whether I could correctly understand your question, how about using fields: "*" for Drive.Permissions.list as follows?

    From:

    pageperm = Drive.Permissions.list (drive.id,{
      supportsAllDrives: true,
      useDomainAdminAccess: true
    })
    

    To:

    pageperm = Drive.Permissions.list(drive.id, {
      supportsAllDrives: true,
      useDomainAdminAccess: true,
      fields: "*" // Added
    })
    

    Note:

    Reference: