Google Drives API - 检索我拥有的文件

md1*_*000 7 google-drive-api

使用 Google Drives API,在检索文件列表时如何制定 Q,以仅检索我拥有的文件?

Tan*_*ike 7

我相信你的目标如下。

  • 您想使用Drive API中的“文件:列表”方法检索您拥有的文件。
  • 您想要创建搜索查询来实现此目的。

为此,这个答案怎么样?

owners在这种情况下,您可以使用字段创建搜索查询。

示例搜索查询:

'me' in owners
Run Code Online (Sandbox Code Playgroud)

如果您想检索特定文件夹中的文件,可以使用以下搜索查询。

'###' in parents and 'me' in owners
Run Code Online (Sandbox Code Playgroud)

示例卷曲:

curl \
  'https://www.googleapis.com/drive/v3/files?q=%27me%27%20in%20owners&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed
Run Code Online (Sandbox Code Playgroud)

curl \
  'https://www.googleapis.com/drive/v3/files?q=%27%23%23%23%27%20in%20parents%20and%20%27me%27%20in%20owners&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed
Run Code Online (Sandbox Code Playgroud)

笔记:

  • 如果您想检索文件夹而不公开共享,请使用访问令牌而不是 API 密钥。请小心这一点。

参考: