Alex
Alex

Reputation: 2449

Programmatically check when google sheets spreadsheet was last updated

I am starting to pull data from multiple shared spreadsheets on google sheets and this works fine. Currently I have to read in the whole spreadsheet and process the data to see if any updates have been made to it. How can I programmatically (in Python 3.9) get a timestamp of the last update to a google sheet?

Upvotes: 1

Views: 1470

Answers (1)

Tanaike
Tanaike

Reputation: 201378

In this case, I thought that "Files: get" of Drive API might be able to be used. In your situation, when googleapis for python is used, how about the following sample script? About service = build("drive", "v3", credentials=creds), in this case, you can see it at Quickstart for python. In this case, fileId is the spreadsheet ID.

service = build("drive", "v3", credentials=creds) # Please use your authorization script here.
fileId = "###" # Please set spreadsheet ID.
res = service.files().get(fileId=fileId, fields="modifiedTime").execute()
print(res)

By this sample script, the last modified time is retrieved.

If you will use requests, how about the following sample script? In this case, please use your access token.

fileId = "###" # Please set spreadsheet ID.
headers = {"Authorization": "Bearer ###your access token###"}
res = requests.get("https://www.googleapis.com/drive/v3/files/" + fileId + "?fields=modifiedTime", headers=headers)
print(res.text)

Reference:

Upvotes: 3

Related Questions