404 “Change not found” message of push notificatio

2019-07-21 21:09发布

问题:

I have a question about push notification API.

I've created web_hook URL under my service for push notification, so I can fetch URL for document change status with selfLink.

But I get 404 codes sometimes when I fetch URL with selfLink.

Please let me know why Drive API response 404 code sometimes.

Scenario:

Request body from google push notification server.

{
  "kind": "drive#changes",
  "id": "12345",
  "selfLink": "https://www.googleapis.com/drive/v2/changes/12345"
}

Fetch URL under my server.

GET https://www.googleapis.com/drive/v2/changes/12345 

Response body

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Change not found: 12345"
   }
  ],
  "code": 404,
  "message": "Change not found: 12345"
 }
} 

回答1:

A change made to a file is invalidated by a subsequent change to the file.

Lets say you have change #100, and get a push notification for it. Between the time the change was sent to you, lets say another edit was made to the file, with a changestamp of 101. Now changestamp 101 will invalidate changestamp 100.

One way to deal with this might be to get changes >= the change number that you get, and filter by fileId.

Also of note opening a file, even if you don't make any edits, updates it's lastViewed time, and thus generates a new change, thereby invalidating the older changestamp.