首页 > 解决方案 > GoogleDrive API & Curl:如何只列出我自己的文件

问题描述

我想列出我在 Google Drive 中的所有文件(不是与我共享的文件,只有我自己的文件)。

我正在尝试使用什么:https ://developers.google.com/drive/api/v3/reference/files/list

我已经能够授予 OAuth、访问令牌和一切。

curl \
  'https://www.googleapis.com/drive/v3/files?corpora=user&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

预期结果是我所有文件的列表,结果是与我共享的文件的部分列表。

标签: curlgoogle-drive-api

解决方案


As you may see in the documentation of the endpoint, the call has an optional parameter called pageSize. That parameter defines the amount of results you will get, and has a default value of 100.

  • pageSize parameter (as in the documentation, November 7th 2019)

The maximum number of files to return per page. Partial or empty result pages are possible even before the end of the files list has been reached. Acceptable values are 1 to 1000, inclusive. (Default: 100)

In order to obtain all your results, in case that the amount is lower than 1000 you can just set that parameter to 1000 and obtain all the results. In case it is not, you will have to create a for loop and make several calls. You can see more on how to use pagination on Google APIs in this link.


推荐阅读