Willis
Willis

Reputation: 777

How can I search files/folders from GoogleDrive not including files in the trash via api v3?

I've got a file abcd.jpg in my GoogleDrive, now I want to check if there's a file called abcd.jpg via Google api v3.

According to Files: list and search-files, I can send a GET request to this url(of course access_token needed):

https://www.googleapis.com/drive/v3/files/?q='root' in parents and name='abcd.jpg'

Here is the response, it's the result what I expected:

{
 "kind": "drive#fileList",
 "incompleteSearch": false,
 "files": [
  {
   "kind": "drive#file",
   "id": "1CF5V4rWTbJLbZAH2dPo0DTFBKdO_WwxX",
   "name": "abcd.jpg",
   "mimeType": "image/jpeg"
  }
 ]
}

My question

If I remove the file abcd.jpg to trash, and request the URL above again, guess what? Totally same response as above as if I did't remove the file at all, but I'm 100% sure I've remove it to trash. So this means files in trash can be retrieved too, anyone who knows how to avoid this? (Please don't let me delete the file in the trash permanently, I don't think this is the best solution.)

Upvotes: 3

Views: 1135

Answers (1)

Tanaike
Tanaike

Reputation: 201378

My understanding of your requirements:

  • You want to retrieve the files without including the trash box in Google Drive using Drive API.

In this case, please use trashed = false for the search query of the method of Files: list in Drive API. The default value is true. Using this, the files without including the trash box can be retrieved.

Modified endpoint:

https://www.googleapis.com/drive/v3/files/?q='root' in parents and name='abcd.jpg' and trashed=false

or

https://www.googleapis.com/drive/v3/files?q=%27root%27%20in%20parents%20and%20name%3D%27abcd.jpg%27%20and%20trashed%3Dfalse

References:

Upvotes: 3

Related Questions