获取“我的云端硬盘"中的文件列表在2020年6月1日之后使用Google Drive API?

获取“我的云端硬盘

问题描述:

我知道Google Drive API将在2020年中期强制执行更新.但是,我对Drive API文档非常困惑,如 Changes.list :

I know Google Drive API will enforce an update in the Mid of 2020. However, I am very confused about the Drive API document, as described in Files.list and Changes.list :

supportsAllDrives :已弃用-请求的应用程序是否同时支持我的驱动器"和共享驱动器.此参数仅在2020年6月1日之前有效.此后,假定所有应用程序都支持共享驱动器. (默认值:false)

supportsAllDrives : Deprecated - Whether the requesting application supports both My Drives and shared drives. This parameter will only be effective until June 1, 2020. Afterwards all applications are assumed to support shared drives. (Default: false)

includeItemsFromAllDrives :已弃用-结果中是否应同时包含我的云端硬盘"和共享驱动器项目.此参数仅在2020年6月1日之前有效.此后,共享驱动器项将包括在结果中. (默认值:false)

includeItemsFromAllDrives: Deprecated - Whether both My Drive and shared drive items should be included in results. This parameter will only be effective until June 1, 2020. Afterwards shared drive items will be included in the results. (Default: false)

我的问题是:

  1. 这是否意味着 supportsAllDrives &如果API请求中未包含(或设置为false)这两个参数, includeItemsFromAllDrives 会在2020年6月1日之后自动变为 true 吗?

  1. Does this mean the supportsAllDrives & includeItemsFromAllDrives will automatically become true after Jun 1,2020, if these two parameters are not included (or are set to false) in the API requests?

在2020年6月1日之前,我们可以通过设置 supportsAllDrives & includeItemsFromAllDrives 设置为false.但是,在2020年6月1日之后,如何仅在我的云端硬盘"中检索文件?我知道我们可以过滤Files.list请求返回的结果,以摆脱共享驱动器中的文件,但是效率很低.应该有一种直接的方法来仅在我的云端硬盘"中获取文件列表.

Before Jun 1, 2020, we can easily retrieve files only in "My Drive" (without files in shared drives) by setting supportsAllDrives & includeItemsFromAllDrives to false. But after Jun 1, 2020, how can I retrieve files only in "My Drive"?? I know we can filter the result returned by the Files.list requests to get rid of the files in shared drives, but it is very inefficient. There should be a direct method to get the file list in "My Drive" only.

1- supportAllDrives & includeItemsFromAllDrives 在默认情况下将变为true.

1 - supportAllDrives & includeItemsFromAllDrives will become true by default.

2-由于没有直接方法来检索您自己的文件,因此您必须使用 q 参数rel = "noreferrer">驱动器:列表 .

2 - Since there is no direct method to retrieve your own files, you have to use the q parameter on the Drive : list.

您有两个选择:

'root' in parents这将使您在我的云端硬盘" 中拥有的文件和文件夹(不包括共享的文件和文件夹),但不会显示文件夹中的文件,仅显示我的云端硬盘.

'root' in parents This will get you the files and folders you have on your My Drive excluding the shared ones, but it will not show files inside folders, just the ones in the front page of My Drive.

最佳方法:

'me' in owners这将使您拥有所有文件.这是最好的选择,因为您不能将所有者强制为共享驱动器项目.

'me' in owners This will get you all the files you own. This is the best option since you can't enforce an owner to a shared drive item.

如果您试图将自己强制为共享驱动器项的所有者,那么您将获得以下信息:

If you try to enforce yourself as an owner of a shared drive item, this is what you will get:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "ownerOnTeamDriveItemNotSupported",
    "message": "Owner role is invalid for shared drive items."
   }
  ],
  "code": 403,
  "message": "Owner role is invalid for shared drive items."
 }
}

引用文档:

ownersownerNamesownedByMe-共享驱动器中的文件归共享驱动器所有,而不是单个用户所有.

owners, ownerNames, ownedByMe — Files within a shared drive are owned by the shared drive, not individual users.

我建议您也使用 q 参数中的trashed = false,以确保搜索到的文件中没有垃圾文件.

A part from that i recommend you to also use trashed = false in the q parameter, to be sure no trashed files appear on your search.

如果要将其作为功能请求提出,则可以转到问题跟踪器

If you want to file this as a feature request you can go to Issue Tracker