0
votes

I have an issue with Google drive API

I have a requirement to do pagination with results to show only files with page limit of 50. I did this using following query.

"Id in parents and mimeType != 'application/vnd.google-apps.folder' and trashed = false"

But in output I see page limit varying all the time. Some times showing 47,46,..so on. Rarely 50.

I think this issue is because of filtering folders after get 50 files and returning response from API to my application.

Is there any other way to get pagination correctly and retrieve only files from API calls


Thanks for reply. Actually I have a requirement to do pagination with files limit(Only files) of 50 per page in order to resolve session time out issue often faced with Google Drive.

Consider Following Scenario: I have 200 files in my folder among which [98 files+102 folders] with page limit of 100.

1st request to API: Internally fetches 100[files+folders] and returns 98 files and page token to my application.

Issue : According to my requirement I should show 100 files per page but now I am showing only 98 saying we have more files available because I got next page token. If i try to check if more files available before enabling view more option this causes more API calls till it finds files or till page token is null which may increase probability of session timeout.

2nd request to API: Because view more is enabled when user clicks it we don't fetch anything because remaining are folders.

Is there any other way to fulfill my requirement to reduce session timeout issue.

1
Is there any possibility of sorting files and folders? so that once I see a folder I can ignore remaining entries.user3111058

1 Answers

2
votes

No. The pagination done by the Drive API is not intended to be a direct one-to-one fit to how your app displays results.

This is particularly noticeable if you are using drive.file scope. afaik, the API layer will request maxResults items from the Drive infrastructure, and then filter out any items that your app is not entitled to see. In the extreme, this could result in zero results, if all (say) 50 items have no permissions.

So you need to more or less ignore the maxCount and simply keep looping through nextPage. The natural temptation is to set it to the maximum of 1000 to reduce paging. Nice idea, but that will often lead to internal timeouts within Google. Therefore my recommendation is to leave it at its default (ie. 100) as this is likely to be the most tested and hence most reliable setting.