Muhammad Zubair KHan
Muhammad Zubair KHan

Reputation: 15

google drive not listing more then 100 File records

I am trying to get all Files and Folders from My Google Drive but it always returns 100 items. I am also unable to understand the nextPageToken and PageSize which is set to 1000 but record returns is 100. I am doing something wrong but don't know. if someone answer then plz explain nextpageToken with Example.

public static List<GoogleDriveFiles> GetDriveFiles(string nextPageToken)
        {
            Google.Apis.Drive.v3.DriveService service = GetService_v3(); // Getting Services

            // Define parameters of request.
            Google.Apis.Drive.v3.FilesResource.ListRequest FileListRequest = service.Files.List();
                      
            FileListRequest.Fields = "nextPageToken, files(*)";
            FileListRequest.PageSize = 1000;
           // FileListRequest.Q = "mimeType='application/vnd.google-apps.folder'";

            // List files.
            IList<Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files;            
            List<GoogleDriveFiles> FileList = new List<GoogleDriveFiles>();
            //files = files.Where(x => x.MimeType == "application/vnd.google-apps.folder").ToList();
            if (files != null && files.Count > 0)
            {
                foreach (var file in files)
                {
                    GoogleDriveFiles File = new GoogleDriveFiles
                    {
                        Id = file.Id,
                        Name = file.Name,
                        Size = file.Size,
                        Version = file.Version,
                        CreatedTime = file.CreatedTime,
                        discription = file.Description,
                        Parents = file.Parents,
                        WebContentLink = file.WebContentLink,
                        webLink = file.WebContentLink,
                        MimiTypes = file.MimeType
                    };
                    FileList.Add(File);
                }
            }
            return FileList;
        }

The code which is commented i also tried to get folders but still no use

Upvotes: 0

Views: 145

Answers (1)

Kessy
Kessy

Reputation: 2014

Try using the Try this API! of files: list there you can check if the request you are making is correct.

I have been able to get 1000 files returned.

The nextPageToken is a token you have to save and then do another request using this token as the field pageToken, see all the request fields on Files: list parameters

Using this nextPageToken on the next request will get you the extra files the first request could not get.

Upvotes: 1

Related Questions