Requesting to get shared drive List id and drive name in google apps script

Viewed 319

enter image description hereDrive.Drives.List this method only retrived 10 shared Drive List and not able to retrieve all the Drive List in google apps script.

Please find my below code for your reference.

I need list of drive id and list of drive name but I am getting only 10 drive id and name not all the list.

function driveList()
{
const sharedDrive = Drive.Drives.list().items
  .map(drive => ({id:drive.id,name:drive.name}));

drivedata=JSON.stringify(sharedDrive);
driveList=JSON.parse(drivedata);
for(var i=0;i<driveList.length;i++)
{
    Logger.log(driveList[i].id);
    Logger.log(driveList[i].name);
}
}
1 Answers

Update with a third possible reason

It's probably one of the three reasons:

  1. You need to paginate; if your result has a nextPageToken property, you need to go to the next page and get more results, and continue doing so while you still get a nextPageToken. You likely want to use the do while loop here to make sure your request executes at least once.

  2. You simply don't have access to those other shared folders and might want to be check if don't have a multi-login issue.

  3. Drives.list retrieves shared Drives and not shared folders. Given that you are using both terms interchangeably, the third possibility is that you are expecting folders but getting drives instead

Related