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

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

问题描述

我最近删除了Google云端硬盘中的多个文件,并将其移至垃圾箱。我想永久删除它们,但垃圾箱中的文件不能按删除日期排序,但只能修改日期(删除后不更新)。



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



从我可以收集的信息来看,有一个文件属性表明它是否被删除,但不是日期。



我试着寻找这个答案,但如果可能的话,找到它并不容易。有人熟悉API的这个领域吗?



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

解决方案

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



获取数据


  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. 查找传输名称,并选择它,将响应复制到记事本++。

  6. 注意nextPageToken字段,并更新请求的页面令牌,重复第5步,直到nextPageToken不再提前。

我使用 http://www.jsonquerytool.com/ 粘贴记事本++中的数据并查询并找到相关的文件。



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


  1. 粘贴将JSON放入JSON部分
  2. 选择JSPath查询类型
  3. 使用此查询来仔细检查文档名称.changes {.file.trashed = == true} .file.name

  4. 将此查询用于g et ID list to keep.changes {.file.trashed === true} .file.id

  5. 将结果复制到Notepad ++

永久删除



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



自动化



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

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).

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.

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?

解决方案

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.

Getting the data:

  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.

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

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

  1. Paste the JSON into the JSON section
  2. Select JSPath Query Type
  3. Use this query to double-check document name ".changes{.file.trashed === true}.file.name"
  4. Use this query to get ID list to keep ".changes{.file.trashed === true}.file.id"
  5. Copy Results to Notepad++

Permanent Deleting

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.

Automation

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天全站免登陆