Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I search custom file properties using the Google Drive API?

Google Drive allows you to add custom properties to files (https://developers.google.com/drive/v3/web/properties), but they aren't included in the searchable text.

From https://developers.google.com/drive/v3/web/search-parameters:

fullText string contains Full text of the file including name, description, content, and indexable text.

You can only search for exact property matches:

appProperties has { key='additionalID' and value='8e8aceg2af2ge72e78' }

Is there some other way to search the custom properties?

Example: if I have a file with custom property "tags" and value "active banking urgent", how can I get files.list (https://developers.google.com/drive/v3/reference/files/list) to find this file when I search for "urgent"?

like image 754
Graeme Pyle Avatar asked Feb 01 '18 04:02

Graeme Pyle


People also ask

How do I do an advanced search in Google Drive?

Using the search strategies below, you can find exactly what you need with just a few keystrokes. To open the Google Drive advanced search, click on the drop-down arrow at the end of the Google Drive search box, and you will find that you can search by file type, visibility, owner and much more!

Can you search by file type in Google Drive?

Filter your Drive results On your computer, go to drive.google.com. At the top, type a word or phrase into the search box. Fill out any of the following sections: Type: File types such as documents, images, or PDFs.


1 Answers

How about theses methods? Unfortunately, it couldn't find the flexible search for appProperties using q. So in order to achieve what you want to do, I propose the following 2 patterns.

Pattern 1

  1. Retrieve a list of files which have appProperties using files/appProperties as a query parameter.
    • GET https://www.googleapis.com/drive/v3/files?fields=files%2FappProperties
    • Only appProperties from all files on Google Drive is retrieved.
  2. Retrieve the key "tags" and the value "active banking urgent" what you need by a script.
  3. Retrieve files using appProperties has { key='tags' and value='active banking urgent' } for q.

In this pattern, the usage count of APIs are 2.

Pattern 2

  1. Retrieve a list of files which have appProperties using files(appProperties,id,name) as a query parameter.
    • GET https://www.googleapis.com/drive/v3/files?fields=files(appProperties%2Cid%2Cname)
    • appProperties, fileId and filename from all files on Google Drive are retrieved. These parameters are searched as or.
  2. By a script, retrieve elements with the property of appProperties, and retrieve files with the appProperties (key "tags", value "active banking urgent") what you need.

In this pattern, the usage count of APIs are 1.

If this was not useful for you, I'm sorry.

like image 84
Tanaike Avatar answered Sep 25 '22 11:09

Tanaike