[英]Google Drive python client / How to filter list of files with 'ownedByMe' and 'properties'?
I succeed to use the q
parameter to filter files in Google Drive which names are not a given value, with following code.我成功使用
q
参数过滤了 Google Drive 中名称不是给定值的文件,代码如下。
prefix = 'forbidden_name'
res = files.list(
q="name != '" + prefix + "'",
pageSize=800, pageToken=None,
fields='nextPageToken, files(id, name, parents, properties, ownedByMe)').execute()
I use the same service account to create these files and to list them.我使用相同的服务帐户来创建这些文件并列出它们。
I would then like to filter only the ones created by this service account.然后,我想只过滤由此服务帐户创建的那些。 To do so, I tried using
ownedByMe
parameter, as listed in Google Documentation (Google API v3) .为此,我尝试使用
ownedByMe
参数,如Google 文档 (Google API v3)中所列。
But I get following error.但我收到以下错误。
res = files.list(
q="ownedByMe = true",
pageSize=800, pageToken=None,
fields='nextPageToken, files(id, name, parents, properties, ownedByMe)').execute()
HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files?q=ownedByMe+%3D+true&pageSize=800&fields=nextPageToken%2C+files%28id%2C+name%2C+parents%2C+properties%2C+ownedByMe%29&alt=json returned "Invalid Value">
Also, when trying to filter on properties
, for instance with a key data_type
, I get the following error.此外,当尝试过滤
properties
时,例如使用键data_type
,我收到以下错误。
res = files.list(
q="properties['data_type'] = 'whatever'",
pageSize=800, pageToken=None,
fields='nextPageToken, files(id, name, parents, properties, ownedByMe)').execute()
HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files?q=properties%5B%27data_type%27%5D+%3D+%27whatever%27&pageSize=800&fields=nextPageToken%2C+files%28id%2C+name%2C+parents%2C+properties%2C+ownedByMe%29&alt=json returned "Invalid Value">
Please, any idea what is wrong in my code?请问,知道我的代码有什么问题吗? Thanks a lot for your help, Bests,
非常感谢您的帮助,Bests,
Unfortunately, in the current stage, there are no query of ownedByMe = true
and properties['data_type'] = 'whatever'
.不幸的是,在当前阶段,没有对
ownedByMe = true
和properties['data_type'] = 'whatever'
查询。 I think that this is the reason of your issue of Invalid Value
.我认为这是您的
Invalid Value
问题的原因。 So how about the following modification?那么下面的修改呢?
In this pattern, ownedByMe = true
is achieved.在这种模式下,
ownedByMe = true
实现了。 In this case, please use the following search query.在这种情况下,请使用以下搜索查询。
'###' in owners
###
is the email of service account.###
是服务帐户的 email。 In this pattern, properties['data_type'] = 'whatever'
is achieved.在这种模式下,实现了
properties['data_type'] = 'whatever'
。 In this case, please use the following search query.在这种情况下,请使用以下搜索查询。
properties has {key='data_type' and value='whatever'}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.