【问题标题】:Google sheets last opened time stampGoogle 表格上次打开的时间戳
【发布时间】:2021-06-07 13:59:24
【问题描述】:
如何查看在 Google 表格中打开工作表的确切时间戳?我可以在“我上次打开的时间”下看到它的打开日期,但看不到确切的时间(除非今天打开)。谢谢
【问题讨论】:
-
-
viewedByMeTime 可在 Drive API 中使用 Files.get()。但是,您需要提供文件 id 才能获取文件信息。如果您打算打开文件以获取文件 ID,则我查看的时间将相应更新。如果您愿意接受一个解决方案,该解决方案需要您使用 Drive Api 使用多个程序而不打开工作表来获取其 ID,请告诉我,以便我提供有关如何执行此操作的指南
-
标签:
google-sheets
google-sheets-api
【解决方案1】:
请注意,此解决方案只会为您提供您上次查看文件的datetime。当其他用户打开/查看 Google 表格文件时,它不会向您显示 datetime。
- 使用Files.list() 搜索驱动器中的文件。使用
query term 过滤您的搜索。
- 在此示例查询中,我想使用 Google 表格
mimetype 获取驱动器中的所有文件,其中包含“库存副本”的文件 name
使用 API Explorer 的示例请求:
q: mimeType = 'application/vnd.google-apps.spreadsheet' and name = 'Copy of Inventory'
fields:files/name, files/id, files/viewedByMeTime
使用 API 资源管理器的示例响应:
{
"files": [
{
"id": "1-zarWNraQWigfRl6YyjhUpWHEROVaR9BcAxxxxxx",
"name": "Copy of Inventory",
"viewedByMeTime": "2021-05-18T17:12:39.630Z"
}
]
}
注意Drive API v2中的文件名标签是title
示例代码:
function getSheetViewTime() {
var query = 'mimeType = "application/vnd.google-apps.spreadsheet" and title = "Copy of Inventory"';
Logger.log(query);
var files = Drive.Files.list({q:query});
Logger.log(files.items[0].lastViewedByMeDate)
}
结果:
5:53:14 AM Notice Execution started
5:53:16 AM Info mimeType = "application/vnd.google-apps.spreadsheet" and title = "Copy of Inventory"
5:53:16 AM Info 2021-05-18T17:12:39.630Z
5:53:16 AM Notice Execution completed