title: Google Drive Rest API - How to check if file has changed
body: <p><strong>Is there a reliable way, short of comparing full contents, of checking if a file was updated/change in Drive?</strong></p>
  
  <p>I have been struggling with this for a bit. Here's the two things I have tried:</p>
  
  <p><strong>1. File <code>version</code> number</strong></p>
  
  <p>I upload a plain text file to Google Drive (<a href="https://developers.google.com/drive/api/v3/simple-upload" rel="nofollow noreferrer">simple upload</a>, <a href="https://developers.google.com/drive/api/v3/reference/files/update" rel="nofollow noreferrer">update endpoint</a>), and save the <code>version</code> from the <a href="https://developers.google.com/drive/api/v3/reference/files#resource" rel="nofollow noreferrer">file metadata</a> returned after a successful upload.</p>
  
  <p>Then I poll the Drive API (<a href="https://developers.google.com/drive/api/v3/reference/files/get" rel="nofollow noreferrer">get endpoint</a>) occasionally to check if the version has changed.</p>
  
  <p>The trouble is that within a second or two of uploading the file, the version gets bumped up again.</p>
  
  <p>There are no changes to the file content. The file has not been opened, viewed, or even downloaded anywhere else. Still, the version number increases from what it was after the upload.</p>
  
  <p>To my code this version number change indicates that the remote file has been changed in Drive, so it downloads the new version. Every time!</p>
  
  <p><strong>2. The <code>Changes</code> endpoints</strong></p>
  
  <p>As an alternative I tried using the <a href="https://developers.google.com/drive/api/v3/manage-changes" rel="nofollow noreferrer">Changes api</a>.</p>
  
  <p>After I upload the file, I get a <code>page token</code> using <a href="https://developers.google.com/drive/api/v3/reference/changes/getStartPageToken" rel="nofollow noreferrer"><code>changes.getStartPageToken</code></a> or <a href="https://developers.google.com/drive/api/v3/reference/changes/list" rel="nofollow noreferrer"><code>changes.list</code></a>.</p>
  
  <p>Later I use this <code>page token</code> to poll the Changes API for changes, and filter the changes for the fileId of uploaded file. I use these options when polling for changes: </p>
  
  <pre><code>{
      "includeRemoved": false
      "restrictToMyDrive": true
      "spaces": "drive"
  }
  </code></pre>
  
  <p>Here again, there is the same problem as with the version number. The page token returned immediately after uploading the file changes again within a second or two. The new page token shows the uploaded file having been changed.</p>
  
  <p>Again, there is no change to the content of the file. It hasn't been opened, updated, downloaded anywhere else. It isn't shared with anyone else. </p>
  
  <p>Yet, a few seconds after uploading, the file reappears in the changes list.</p>
  
  <p>As a result, the local code redownloads the file from Drive, assuming remote changes.</p>
  
  <hr>
  
  <p><strong>Possible workaround</strong></p>
  
  <p>As a hacky hook, I could wait a few seconds after the file upload before getting the new file-version/changes-page-token. This may take care of the delayed version increment issue.</p>
  
  <p>However, there is no documentation of what is causing this phantom change in version number (or changes.list). So, I have no sure way of knowing:</p>
  
  <ol>
  <li>How long a wait is safe enough to get a 'settled' version number without losing possible changes by other users/apps?</li>
  <li>Whether the new (delayed) version number will be stable, or may change again at any time for no reason?</li>
  </ol>
  
  <hr>
  
  <p><strong>Is there a reliable way, short of comparing full contents, of checking if a file was updated/change in Drive?</strong></p>