简体   繁体   English

Google Drive python 客户端/如何过滤具有“ownedByMe”和“属性”的文件列表?

[英]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 = trueproperties['data_type'] = 'whatever'查询。 I think that this is the reason of your issue of Invalid Value .我认为这是您的Invalid Value问题的原因。 So how about the following modification?那么下面的修改呢?

Pattern 1:模式一:

In this pattern, ownedByMe = true is achieved.在这种模式下, ownedByMe = true实现了。 In this case, please use the following search query.在这种情况下,请使用以下搜索查询。

Modified search query:修改后的搜索查询:

'###' in owners
  • In your case, ### is the email of service account.在您的情况下, ###是服务帐户的 email。

Pattern 2:模式二:

In this pattern, properties['data_type'] = 'whatever' is achieved.在这种模式下,实现了properties['data_type'] = 'whatever' In this case, please use the following search query.在这种情况下,请使用以下搜索查询。

Modified search query:修改后的搜索查询:

properties has {key='data_type' and value='whatever'}

References:参考:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Drive Api客户端:如何获取文件夹中的文件列表 - Google Drive Api Client: How to get the list of files in a folder 如何列出特定谷歌驱动器目录 Python 中的所有文件 - How to list all the files in a specific google drive directory Python 使用python的谷歌驱动器文件夹中的文件列表 - List of files in a google drive folder with python Google Drive Python API客户端对files()。insert()的权限不足 - Google Drive Python API Client insufficient permission for files().insert() 如何使用 V3 API Python 客户端按 ID 列出 Google Drive 文件夹的内容? - How to list the contents of a Google Drive folder by ID with the V3 API Python client? Google Drive API 客户端 (Python):文件权限不足 ().insert() - Google Drive API Client (Python): Insufficient Permission for files().insert() Google Drive API Python 客户端:如何在批量创建时检索已创建的文件夹ID列表? - Google Drive API Python Client: How to retrieve list of created folder IDs when created in batch? Google Colaboratory 中的 Python - 如何在 Google Drive 中创建、写入和读取文件 - Python in Google Colaboratory - How to create, write and read files in google drive 如何使用http请求从谷歌驱动器获取列表文件? - How get list files from google drive with http request? 如何在Python内存中从Google云端硬盘读取(流式传输)文件? - How to read (stream) files from Google Drive in memory in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM