Search code examples
gocachinggoogle-sheetsgoogle-drive-apigdrive

Cannot get the newest revision immediately after the file changed on gdrive


From this issue: https://github.com/googleapis/google-api-go-client/issues/906

using api v3 to list and sync excel files on gdrive.

const fieldsContent = "nextPageToken, files(id, name,version, mimeType, size, md5Checksum,modifiedTime,lastModifyingUser,webViewLink)"
const qInParent     = "'%s'  in parents"
const trashFalse    = " and trashed=false"
func (d *Drive) testList(id string)  {
    var driveService *drive.Service
    var pageToken string
    // .....init the service
    fileList, err := driveService.Files.List().Q(fmt.Sprintf(qInParent, id)+trashFalse).
        Fields(fieldsContent).
        PageSize(pageSize).PageToken(pageToken).Do()
    // ... print the files
}

Just a simple test case.

At 2021-03-04T15:14:16+08:00, got test.xlsx state:

Md5Checksum: 668395eb4b0db465efaf631df3aefd86

ModifiedTime: 2021-03-04T07:13:02.100Z

At 2021-03-04T15:16:06+08:00, got test.xlsx state:

Md5Checksum: 668395eb4b0db465efaf631df3aefd86

ModifiedTime: 2021-03-04T07:13:02.100Z

At 2021-03-04T15:16:28+08:00, got test.xlsx state:

Md5Checksum: 6155d40b7376d8c675c02ebd5a2394e9

ModifiedTime: 2021-03-04T07:13:48.638Z

The file first change at time: 2021-03-04T07:13:02.100Z, second change at time: 2021-03-04T07:13:48.638Z, but through the api, we can not get the changed file's info immediately, may be delayed a few minutes, perhaps 10 minutes sometime.

Update: After edit the file on gdrive , download the file through api within several minutes. Still can not get the latest file, still got the previous one.


Solution

  • @Tanaike i have found the reason. If you test with Docs Editors file looks like this one : enter image description here

    i could use api file.get to export the file and download the latest one. but still cannot obtain the VersionNumber and ModifiedTime immediately, still have a delay about several minutes to get the latest VersionNumber and ModifiedTime

    Please try to test with XLSX file looks like this one, you can not download the latest file and also can not obtain the VersionNumber and ModifiedTime within several minutes after modify and save the file on gdrive.

    enter image description here