I am basically getting the modified time like this:
request = service.files().get_media(fileId=file_id)
data = service.files().get(fileId=l, fields='*').execute()
meta = service.files().get(fileId=l, fields="*", supportsTeamDrives=True).execute()
print(meta["modifiedTime"])
But the printed modified time is different than what the web interface for the Google Drive shows:
u'2020-08-02T12:29:14.658Z'
Why do the date times differ? Am I doing it incorrectly?
CodePudding user response:
The file attribute modifiedTime
and the latest revision timestamp don’t always store the same value, that’s expected behavior.
The code provided fetches the Drive file item attribute modifiedTime
, however the screenshot attached shows the revision list. The modifiedTime
attribute stores the timestamp of the latest modification of an item in Google Drive. Any change to that item would update its value. A revision timestamp however stores the datetime when a new version of the file contents is updated/uploaded.
You can find more information here.
For example, after uploading a new revision of a binary file to Drive, let’s say modifiedTime
is X
and the latest revision timestamp would also be X
. However if I change that item’s description using Drive UI, modifiedTime
is now Y
but the latest revision timestamp would still be X
.
On an additional note, timestamps returned from the API are always in UTC timezone whether timestamps displayed on Drive UI are usually displayed in the local time zone.
If you want to audit/inspect all changes to a specific file in Drive, I’d recommend using Drive Activity API.