Tachyons
Tachyons

Reputation: 2171

How to exclude trashed files when listing files in google drive

I want to list all the files in google drive using google drive api v2 . But I want to exclude files in trash in the list

So I tried

GET https://www.googleapis.com/drive/v2/files?trashed=false

as suggested in the api documentation But still I get files in the trash folder ,Am I missing something ? Or is it a known bug in drive api?

Upvotes: 12

Views: 6378

Answers (2)

Dhunju_likes_to_Learn
Dhunju_likes_to_Learn

Reputation: 1386

If some else also landed here trying to filter out Trashed file when using the Google Drive API, you can use setQ(args...) function like below,

FileList result = service.files().list()
          .setQ("mimeType='image/jpeg' and trashed=false")
          .setSpaces("drive")
          .setFields("items(id, title)")
          .execute();

More here - https://developers.google.com/drive/api/guides/search-files

Upvotes: 2

Tachyons
Tachyons

Reputation: 2171

Problem was with query syntax, proper query parameter was

GET https://www.googleapis.com/drive/v2/files?q=trashed%3Dfalse

Upvotes: 25

Related Questions