如何使用 Google Drive API 检索最近的垃圾文件列表 [英] How to retrieve a recent list of trashed files using Google Drive API

查看:15
本文介绍了如何使用 Google Drive API 检索最近的垃圾文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近删除了 Google 云端硬盘中的大量文件,并将它们移至回收站.我想永久删除它们,但回收站中的文件不能按删除日期排序,只能按修改日期(删除时不更新).

I have recently deleted quite a number of files in Google Drive, and they were moved to the trash. I would like to permanently delete them, but the files in the Trash can't be sorted by Deleted Date, but only Modified Date (which is not updated upon delete).

因此,我想利用 Google Drive API 来枚举垃圾并确定它被丢弃的日期,以找到我想随后永久删除的文件集.

Therefore, I would like to leverage the Google Drive API to enumerate the trash and determine the date it was trashed, to find the set of files I would like to subsequently permanently delete.

据我所知,有一个文件属性表明它是否已被丢弃,但不是日期.

From what I can gather, there is a file property which indicates if it has been trashed, but not the date.

我尝试搜索此答案,但如果可能的话,它并不容易找到.有人熟悉 API 的这个领域吗?

I tried searching for this answer, but it's not easy to find, if it is possible. Is anyone familiar with this area of the API?

有比我尝试的更好的策略吗?

Is there a better strategy than what I am attempting?

推荐答案

直接使用https://developers.google.com/drive/v3/reference/changes/list,您可以检索最近的文件/文件夹更改.这似乎列出了文件夹移动以及已删除文件的这些更改.

Directly using https://developers.google.com/drive/v3/reference/changes/list, you can retrieve your most recent file/folder changes. This would seem to list those changes for folder movements as well as trashed files.

获取数据:

  1. 从 - https://developers.google.com/获取页面令牌drive/v3/reference/changes/getStartPageToken
  2. 将该令牌放入 - https://developers.google.com/drive/v3/reference/changes/list,页面大小为 500,includeRemoved 为 true,并使用字段编辑器链接按钮选择所有字段.
  3. 您将看不到任何结果,因为您使用的是最新的页面令牌.您需要手动减少页面令牌,直到返回的 changes.time 早于所需的日期范围.(查询中没有过滤器).建立正确的页面令牌后,请继续执行以下步骤.
  4. 在执行之前,打开开发者工具(我使用的是 Chrome)并查看网络部分
  5. 查找以changes?pageToken=..."开头的传输名称,然后选择它,将响应复制到 Notepad++
  6. 记下 nextPageToken 字段,并更新请求的页面令牌,重复第 5 步,直到 nextPageToken 不再前进.
  1. Get a page token from - https://developers.google.com/drive/v3/reference/changes/getStartPageToken
  2. Put that token into - https://developers.google.com/drive/v3/reference/changes/list, with page size of 500, includeRemoved on true, and select all fields with the fields editor link button.
  3. You will see no results, because you are using the most recent page token. You need to manually reduce the page token until the returned changes.time is before the desired date range. (There is no filter for this in the query). Once you have established the correct page token, continue with the steps below.
  4. Before Executing, open the Developer Tools (I was using Chrome) and view the Network section
  5. Look for a transfer name staring with "changes?pageToken=...", and select it, copy the Response to Notepad++
  6. Note the nextPageToken field, and update the requested page token, repeating step 5 until the nextPageToken not longer advances.

我使用 http://www.jsonquerytool.com/ 从 notepad++ 粘贴数据并进行查询出来并找到相关的文件ID.

I used http://www.jsonquerytool.com/ to paste the data from notepad++ and to query out and find the relevant fileids.

查询 ID 数据(针对每个返回的结果):

Querying the data for IDs (for each of the results returned):

  1. 将 JSON 粘贴到 JSON 部分
  2. 选择 JSPath 查询类型
  3. 使用此查询仔细检查文档名称.changes{.file.trashed === true}.file.name"
  4. 使用此查询获取 ID 列表以保留.changes{.file.trashed === true}.file.id"
  5. 将结果复制到记事本++

永久删除

如果您有少量 FileID (<100),您可能希望通过 https://developers.google.com/drive/v3/reference/files/delete,并可选择使用 https://developers.google.com/drive/v3/reference/files/get 每次手动迭代.

If you have a small amount of FileIDs (< 100), you may wish to manually run them through https://developers.google.com/drive/v3/reference/files/delete, and optionally check them with https://developers.google.com/drive/v3/reference/files/get on each manual iteration.

自动化

显然,如果您要处理更多数据,那么编写脚本或应用程序来完成上述操作是有意义的.但至少你可以看到这是可能的.

Obviously, if you're dealing with more data it would make sense to write a Script or App to accomplish the above. But at least you can see it's possible.

这篇关于如何使用 Google Drive API 检索最近的垃圾文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆