文件编辑后,Etag和LastModifiedDate不会更改

asi*_*ir6 5 google-docs google-docs-api google-drive-api

在GoogleDrive中编辑文档后,似乎LastModified值有时不会立即更改.看起来价值将在几分钟内更新.

我试图通过DriveSDK获取文档的Etag,它也发生在Etag值上.

这种奇怪的行为使我无法实时获取文档状态(已修改或未修改).任何建议将受到高度赞赏.

[示例请求和响应]请求只是GoogleDrive ListFiles:https://www.googleapis.com/drive/v2/files

这是响应JSON的一部分,您可以看到ModifiedDate早于ModifiedByMeDate.

 {
 "kind": "drive#fileList",
 "etag": "\"3NNCnvnQuji-pODa6SMQ6atlc3M/oKnf21kAcJKTCIycS597xCSR2bk\"",
 "selfLink": "https://www.googleapis.com/drive/v2/files",
 "items": [
  {
   "kind": "drive#file",
   "id": "1lZjcJIf3Chuu5upFqtiqfTRnRw7*****rFL_tlO8A",
   "etag": "\"3NNCnvnQuji-pODa6SMQ6atlc3M/MTM1NDY5MzMyMzQ1Mg\"",
   "selfLink": "https://www.googleapis.com/drive/v2/files/1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A",
   "alternateLink": "https://docs.google.com/a/*****.com/document/d/1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A/edit",
   "embedLink": "https://docs.google.com/a/*****.com/document/d/1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A/preview",
   "iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_11_document_list.png",
   "thumbnailLink": "https://docs.google.com/feeds/vt?gd=true&id=1lZjcJIf3Chuu5upFqtiq*****7wSUjbRurFL_tlO8A&v=22&s=AMedNnoAAAAAU*****UK74n3UiIg0L4TY-NwP3EaAU&sz=s220",
   "title": "TestFile",
   "mimeType": "application/vnd.google-apps.document",
   "labels": {
    "starred": false,
    "hidden": false,
    "trashed": false,
    "restricted": false,
    "viewed": true
   },
   "createdDate": "2012-07-24T08:14:13.918Z",
   "modifiedDate": "2012-12-06T01:49:57.982Z",
   "modifiedByMeDate": "2012-12-06T01:49:57.982Z",
   "lastViewedByMeDate": "2012-12-06T01:50:06.974Z",
   "parents": [
    {
     "kind": "drive#parentReference",
     "id": "0AJ-aGTt-gWksUk9PVA",
     "selfLink": "https://www.googleapis.com/drive/v2/files/1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A/parents/0AJ-aGTt-gWksUk9PVA",
     "parentLink": "https://www.googleapis.com/drive/v2/files/0AJ-aGTt-gWksUk9PVA",
     "isRoot": true
    }
   ],
   "exportLinks": {
    "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "https://docs.google.com/feeds/download/documents/export/Export?id=1l*****huu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A&exportFormat=docx",
    "application/vnd.oasis.opendocument.text": "https://docs.google.com/feeds/download/documents/export/Export?id=1lZjcJIf3Chuu5upF*****SUjbRurFL_tlO8A&exportFormat=odt",
    "text/html": "https://docs.google.com/feeds/download/documents/export/Export?id=1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUj*****L_tlO8A&exportFormat=html",
    "application/rtf": "https://docs.google.com/feeds/download/documents/export/Export?id=1lZjcJIf3Chuu5upFqtiq*****SUjbRurFL_tlO8A&exportFormat=rtf",
    "text/plain": "https://docs.google.com/feeds/download/documents/export/Export?id=1lZjcJIf3Chuu5upFqtiqf*****SUjbRurFL_tlO8A&exportFormat=txt",
    "application/pdf": "https://docs.google.com/feeds/download/documents/export/Export?id=1lZjcJIf3C*****fTRnRw7wSUjbRurFL_tlO8A&exportFormat=pdf"
   },
   "userPermission": {
    "kind": "drive#permission",
    "etag": "\"3NNCnvnQuji-pODa6SMQ6atlc3M/6LfqbkrWujmUe1WSDkyhTxdIUCc\"",
    "id": "me",
    "selfLink": "https://www.googleapis.com/drive/v2/files/1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A/permissions/me",
    "role": "owner",
    "type": "user"
   },
   "quotaBytesUsed": "0",
   "ownerNames": [
    "***** *****"
   ],
   "lastModifyingUserName": "***** *****",
   "editable": true,
   "writersCanShare": true,
   "appDataContents": false
  },
Run Code Online (Sandbox Code Playgroud)

小智 6

这不回答这个问题,但我想就资源的内容etagmodifiedDate方法发表意见File.File etag似乎只是直接对应于modifiedDate价值.etag(斜杠之后)的第二部分只是一个编码modifiedDate.

在Documents List API中,app:edited除了updated属性之外还有一个被称为属性的属性(这似乎与modifiedDate此处对应).这些时间戳改变的方式没有明确记录,但我注意到app:edited几乎每一个变化(例如文件的主演,甚至是另一个用户,如果我没记错)和updated更改的更改都更加有限(例如,内容修改和权限更改) ).并且etag之前直接对应app:edited,这很好,因为更改app:edited表示确实存在更改(有时它会变化太多,例如由不同用户对文件进行主演,因为它不会真正影响当前用户的元数据).

我想说的是,我认为Documents List etag(并且具有app:edited属性)比modifiedDate仅具有Drive API更好.后者的问题是您没有可靠的方法来确定File资源是否已更改.例如,如果您只想检查File资源是否已更改,则可以使用带有If-None-Match标头的files.get方法etag.但etag并不总是改变,因为modifiedDate并不总是改变.例如,当有新内容,更改ACL或更改描述时,它会更改,但不会更改,例如,在删除或父项更改时.比较两个资源时,您无法可靠地确定哪个资源更新.添加modifiedDate可以设置的事实(例如,可以将其设置modifiedDate为更早的值,甚至是常量值,并etag使用它).etag失去了预期的目的.在许多情况下,我们不能仅仅依赖于更改列表,如果etag行为正常,这将对确定发生的更改有很大帮助.

我建议的是恢复etag类似于Documents List API的行为.并且为了帮助确定哪个资源有更新的信息,也要添加回app:edited属性(我认为只记录值etag就足够了,就像正式说第二部分是时间戳的编码一样,这样我们就可以依赖它了永远在增加).此外,我认为最好只更改modifiedDate内容修改的属性,而不是其他任何内容(例如,不更改ACL或描述更改).

同样,逐字文件etagRevision(List)资源也不是很有用.由于downloadUrl属性会定期更改,因此etag每个Revision列表和整个列表的s都会随之更改,因此无法使用(因为您无法使用它来检查修订版本是否未更改).好东西有md5Checksum你可以比较的属性,但在某些情况下它不可靠.


pin*_*yid 2

Google 的基础设施在更新后异步更新 Google 文档。据我所知,这会影响 etag、缩略图,可能还影响 md5sum 和某些修改日期。

Google 的一些文档确认了哪些项目是异步的,哪些是同步的,这对开发人员来说非常有用。