如何使用任何类型的 API 或 Google Drive API in PHP 获取 google sheet 的最后更新时间

How to get the last updated time of google sheet using any kind of API or Google Drive API in PHP

我需要知道 Google sheet 上次编辑时的更新时间。 这个APIhttps://spreadsheets.google.com/feeds/cells/sheetID/1/public/full?alt=json 没有正确检索它所说的最后更新时间。

我应该应用什么技巧或方法来获得任何上次更新时间的正确日期时间 Google sheet。谢谢

  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'];
}

从您的脚本中,我了解到您的电子表格是公开共享的。在这种情况下,作为一种方法,使用 API 键在 Drive API 中使用“Files:get”的方法来检索 modifiedTime 的值怎么样?当这反映到您的脚本中时,它会变成如下。

在这种情况下,需要使用 API 密钥才能使用驱动器 API。请注意这一点。

发件人:

$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'];

收件人:

$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'];

参考: