Google drive rest API, Download files from root folder only

拟墨画扇 提交于 2019-12-06 22:12:41

There are a number of considerations.

Your line 3 needs to be

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

FileList result = serv.files().list().setFields("*").setQ(q).setMaxResults(10).execute();

You need to be aware that this will return a maximum of 10 results, but even more so, you need to be aware that there is no minimum number of results. This means that if you have 11 files, you might get 10 in the first iteration and 1 in the 2nd. However, you could also get 1 and 10, or 3 and 6 and 2, or 0 and 0 and 1 and 10. You need to keep fetching results until the value of getNextPageToken() == null. So your line

if (listA == null || listA.isEmpty()) {

should be something like

if (result.getNextPageToken() == null) {

I realise that you've copy/pasted from the official documentation, but sadly that documentation is wrong.

You need to use the Q parameter to search

q string A query for filtering the file results. See the "Search for Files" guide for supported syntax.

Sending something like the following will return everything that is not a folder with the parent of root.

mimeType != 'application/vnd.google-apps.folder' and 'root' in parents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!