I want to query only the top level files from a google drive using java api (v3). (By top level, I mean I don't want to go recursively into folders)
I checked this question, but it does not seems to have a proper solution(even though it has a accepted solution).
I have tried couple of things :
1) I tried setting the Query
// this gives the shared files, but gives all files, not just the top files
Files.List request = drive.files().list().setQ("sharedWithMe = true");
2) I read somewhere that top level files in shared with me does not have any parent, So I tried to get files which does not have any parent
Similar to 'root' in parents for My Drive files, I tried couple of queries :
drive.files().list().setQ("sharedWithMe = true and null in parents");
drive.files().list().setQ("sharedWithMe = true and parents = null");
but they does not seem to work.
3) I tried getting all the files and then tried to select files only which has does not have parent.
Files.List request = drive.files().list()
.setQ("sharedWithMe = true)
.setFields("nextPageToken, files(id, name, parents)");
even after including parents in output fields, File.getParents() gives NULL(even for files which have parent).
Question :
Is there a way we can get parents information for each file with Files.list()?
Is there a way to get files at top level of shared with me folder?(by adding some query along with sharedWithMe = true)