使用 Google Drive API 在 .NET 中获取文档的修订历史

Getting revision history of a document in .NET using Google Drive API

我正在尝试找到一种方法来获取 google 文档的修订历史记录。

我有以下代码 returns Revisions:

var _driveService = GetDriveServiceInstance();
RevisionList revisions = _driveService.Revisions.List(fileId).Execute();

但是,我无法获取对文档所做的更改。例如,添加或删除的字词。

我发现 this resource 他们在 R 中完成了相同的任务:

url <- modify_url(
  url = "https://docs.google.com/feeds/download/documents/export/Export",
  query = list(
    id = fileId,
    revision = revisionId,
    exportFormat = "txt"
  )
)

在此代码中,他们 运行 可以提供 revisionIdfileId 的查询。但是,我找不到在 ASP.NET.

我自己的代码中将这些参数合并到 Revisions.List(fileId) 中的方法

我想知道我该怎么做。有办法吗?我在 Internet 上找不到任何资源。

您正在使用列表方法 [1],它将为您检索所有修订的列表及其每个修订的属性,这些在此处指定 [2]。如果您想获得与修订 ID [3] 相关的特定修订,您可以使用 get 方法。

如您所见,没有属性可以知道是否添加或删除了单词。但是 exportLinks 属性是一个 JSON,带有各种链接,可以下载不同文件类型(html、pdf 等)[4].

在您发布的资源中,他们使用一种变通方法来获取链接,因为 URL 始终采用相同的格式,您只需要更改 URL 上的参数(文件ID、修订 ID 和文件类型):

 https://docs.google.com/feeds/download/documents/export/Export?id=FileID&revision=RevisionID&exportFormat=FileType

您必须获取那些 URLs 才能在您的代码中获取文件,阅读它并查看进行了哪些更改。此外,请记住,如果该文件并非 public 供所有人使用,您将需要具有正确权限的凭据才能下载该文件(通过浏览器或代码)。

[1] https://developers.google.com/resources/api-libraries/documentation/drive/v3/csharp/latest/classGoogle_1_1Apis_1_1Drive_1_1v3_1_1RevisionsResource_1_1ListRequest.html

[2] https://developers.google.com/drive/api/v3/reference/revisions

[3] https://developers.google.com/resources/api-libraries/documentation/drive/v3/csharp/latest/classGoogle_1_1Apis_1_1Drive_1_1v3_1_1RevisionsResource_1_1GetRequest.html

[4]https://developers.google.com/resources/api-libraries/documentation/drive/v3/csharp/latest/classGoogle_1_1Apis_1_1Drive_1_1v3_1_1Data_1_1Revision.html