Reputation: 163
Currently, I'm using Files: list
API below to get all the files
https://developers.google.com/drive/api/v3/reference/files/list
Attached screenshot contains the parameters used where I've provided (pagesize=1000). This only returns 1000 files per call. I have to set (pageToken='nextPageToken' value from previous response)
Is there a way to for the API to return all the files instead of having to set (pageToken='nextPageToken' value from previous response) ?. Please advise
Upvotes: 1
Views: 4522
Reputation: 3
I don't know what programming language you use but in dotnet I have something like this and thanks to this I can get all files that drive has.
var listRequest = _driveService.Files.List();
listRequest.Q = $"'{_appSettings.GoogleDrive.FolderId}' in parents";
// If we set the page size maximum we can get all files in one request to not wait the 100-100 increasing..
listRequest.PageSize = 1000; // Default 100 Maximum 1000
listRequest.Fields = "nextPageToken, files(id, name)";
var listResponse = await listRequest.ExecuteAsync();
If there is another page listResponse will return with "NextPageToken". With the help of this property you can again request. Utilizing a loop you can collect all of the files that folder has.
Upvotes: 0
Reputation: 53
Also note that my testing suggests that you get 100 back for My Drives and 460 (?) for Shared Drives. I have never got 1000 back for either type. You will need to iterate each "page" in turn
Upvotes: 0
Reputation: 116868
Answer: No there is no way to List more then 1000 files without pagination.
Addional information.
If you check the documentation that you yourself have linked
You will notice that it states that the default page size is 100, that means that if you don't send the page size parameter that it will automatically be set to 100 by the system.
You will also notice that it states Acceptable values are 1 to 1000, inclusive.
this means that you can max set pagesize to 1000
If you want additional files you need to use the nextpagetoken to get another set of rows.
There is no other way around pagination if you want more then the 1000 rows. I dont know what your doing but maybe using the the Q parameter to search for just the files you are looking for and thereby limiting the response to under 1000.
Upvotes: 1