Snake Eyes
Snake Eyes

Reputation: 16764

List items based on a property key in Google Drive API v3 and .NET

I succeeded to manage my issue: List folders which has not a custom property in Google Drive API v3 and .NET

Now, I have other challenge.

I have custom property called imdb and it has any value (not empty).

I tried to figure out how to retrieve those items which have imdb property in list (no matter what value have). I don't want getting entire full list and check one by one the Properties dictionary (I have 300-320 items and is growing).

request.Q = $"mimeType='application/vnd.google-apps.folder' and properties has {{ key='imdb' and value='/*WHAT SHOULD DO ?*/' }}"; 

Seems that query works only if provide both components key and value, otherwise I will get 400 as well

I tried also:

request.Q = $"mimeType='application/vnd.google-apps.folder' and properties has {{ key='imdb' and value!='' }}";

but it gave me 400 (bad request), seems value!='' is not valid

The request object is:

var request = dataService.Files.List();

and

...
dataService = new DriveService(new BaseClientService.Initializer
  {
    HttpClientInitializer = credential,
    ApplicationName = "XXXX"
});

Any advice ?

Upvotes: 2

Views: 607

Answers (1)

ziganotschka
ziganotschka

Reputation: 26836

As for now, it is not possible to query for properties without specifying the exact value

This issue is being investigated by Google. As a consequence, you can not use the not, contains or other operators that would be helpful for your query. All you can do (not particularly efficient) is to

  • list all of you files specifying fields to files/properties
  • filter the list manually for the results where files/properties is not empty
  • compare the filtered list against the results of request.Q = $"'{id}' in parents and (properties has {{ key='xxx' and value='' }} or not properties has {{ key='xxx' and value='' }})";

I would recommend you to comment on the existing issue to remind Google that it still has not been implemented.

Upvotes: 1

Related Questions