1

I need to know when a Google sheet is updated last time it was edited. This API https://spreadsheets.google.com/feeds/cells/sheetID/1/public/full?alt=json doesn't retrieve the last updated time correctly it says.

What tricks or method should I apply to get the correct date-time of last updated time of any Google sheet. Thanks

  public function get_json_data() {
    $sheet_url = "https://spreadsheets.google.com/feeds/cells/1t7MnIPlu_lU9srlftEvtSnSx3db3-hLctNXFao3wRVQ/1/public/full?alt=json";
   
    $res = file_get_contents($sheet_url);
    return json_decode($res, true)['feed'];
}
AR. Arif
  • 93
  • 1
  • 8
  • Can you provide your current script? – Tanaike Jun 17 '21 at 06:02
  • @Tanaike I have shared the code but they says this API don't provide the last updated time. its only provide current time this is one of the same qustion ask here https://stackoverflow.com/questions/43411138/get-google-sheets-last-edit-date-using-sheets-api-v4-java – AR. Arif Jun 17 '21 at 06:22
  • Thank you for replying and adding more information. From your updated question, I proposed an answer. Could you please confirm it? If that was not the direction you expect, I apologize. – Tanaike Jun 17 '21 at 06:57

1 Answers1

2

From your script, I understood that your Spreadsheet is publicly shared. In this situation, as a method, how about retrieving the value of modifiedTime using the method of "Files: get" in Drive API with the API key? When this is reflected to your script, it becomes as follows.

In this case, the API key is required to be used for using Drive API. Please be careful this.

From:

$sheet_url = "https://spreadsheets.google.com/feeds/cells/1t7MnIPlu_lU9srlftEvtSnSx3db3-hLctNXFao3wRVQ/1/public/full?alt=json";

$res = file_get_contents($sheet_url);
return json_decode($res, true)['feed'];

To:

$api_key = "###"; // Please set your API key.
$sheet_url = "https://www.googleapis.com/drive/v3/files/1t7MnIPlu_lU9srlftEvtSnSx3db3-hLctNXFao3wRVQ?fields=modifiedTime&key=" . $api_key;
$res = file_get_contents($sheet_url);
return json_decode($res, true)['modifiedTime'];

Reference:

Tanaike
  • 181,128
  • 11
  • 97
  • 165