【问题标题】:Invalid Query, Drive api, files.list()无效的查询、驱动器 api、files.list()
【发布时间】:2016-10-29 13:15:25
【问题描述】:

这个函数:

drive.ListFile({'q': " id = '"+Value+"' and trashed=false"}).GetList()

return: "无效查询"

问题在于选择器'id',如果我提出这个条件,我会返回一个带有参数'id'的字典

我用过这个文档, https://developers.google.com/drive/v2/reference/files/listhttps://developers.google.com/drive/v3/web/search-parameters

它适用于其他选择器,但对于 'id' 不应该

【问题讨论】:

  • “[...] 但对于 'id' 它不应该是”是什么意思?不应该是什么?

标签: python google-drive-api drive pydrive


【解决方案1】:

编辑:您可以通过以下方式访问元数据,并通过其 ID 获取和设置现有文件的内容。

# Calling CreateFile() with an existing ID links it to the already existing file.
gdrive_file = drive.CreateFile({'id': '<your file id>'})
gdrive_file.FetchMetadata() # Only needed if you want to view or edit its metadata.
# Do things with metadata here as needed.

gdrive_file.GetContentFile('dog.png') # Download content file.

# And/or upload a new content file.
gdrive_file.SetContentFile('cat.png') 
gdrive_file.Upload()

当然,docs 有很多例子。

原创: 看看docs for file listings 的例子。

确保你

  1. 不要在= 标志周围引入自己的空间,
  2. PyDrive 使用 Google Drive API v2,因此请务必改用 the v2 search parameter page
  3. ID 是 Google Drive 分配的文件夹 ID,this SO question 列出了查找 ID 的方法。

例如:

from pydrive.drive import GoogleDrive

drive = GoogleDrive(gauth) # Create GoogleDrive instance with authenticated GoogleAuth instance
folder_id = "insert your folder ID here"

# Auto-iterate through all files in the specified folder.
file_list = drive.ListFile({
    'q': "{id} in parents and trashed=false".format(id=folder_id)
}).GetList()

for file1 in file_list:
  print('title: %s, id: %s' % (file1['title'], file1['id']))

【讨论】:

    【解决方案2】:

    id 是不支持进行文件搜索的查询字段。

    查看文档for Drive API v2 以查看要搜索的有效字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-15
      • 2011-08-09
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 2012-12-24
      • 2018-02-04
      • 1970-01-01
      相关资源
      最近更新 更多