使用获取Google文档中文档的修订提要.NET

本文关键字:文档 NET 中文 获取 Google | 更新日期: 2023-09-27 17:58:04

我正在尝试获取谷歌文档中现有文档的修订提要(实际上我只需要修订计数)。我使用下面的代码并获得一个GDataRequestException。内部异常为404,而响应字符串为(文档id被截断):

<errors xmlns='http://schemas.google.com/g/2005'>
  <error>
    <domain>GData</domain>
    <code>ResourceNotFoundException</code>
    <internalReason>Invalid document id: file:0BxwzFL2fD0</internalReason>
  </error>
</errors>

这是代码:

var documentsService = new DocumentsService("myappname");
documentsService.SetAuthenticationToken(token);
var uri = string.Format("https://docs.google.com/feeds/default/private/full/{0}/revisions", Uri.EscapeDataString(resourceId));
var query = new DocumentsListQuery(uri);
var feed = documentsService.Query(query);

使用获取Google文档中文档的修订提要.NET

您使用的resourceId似乎无效。您不应该手动构建uri,而应该使用想要检索修订的DocumentEntry实例的RevisionDocument属性:

var uri = entry.RevisionDocument;
var documentsRequest = new DocumentsRequest();
// ... do any authentication here..
var revisions = documentsRequest.Get<Google.Documents.Document>(entry.RevisionDocument).Entries;