首页 > 解决方案 > 是否可以在 Google Apps 脚本中创建 getCommenters() 功能?

问题描述

Google Apps Script的DriveApp > File 类提供以下方法:

getCommenters方法不可用。(这很有趣,因为addCommenteraddCommentersremoveCommenter方法可用。)

我正在制作一个脚本,我正在根据电子表格中的电子邮件地址更改文件和文件夹权限。我想要一个getCommenters功能,以便我可以比较电子表格中的评论者电子邮件是否已经是文件的评论者,因此无需再次使用addCommenters. (按下它会为用户生成一封新电子邮件。)使用查看器和编辑器执行此操作没有问题,因为方法是可用的。

问题:是否有可能创建一个模仿假设功能的函数getCommenters?或者至少提取评论者的一系列电子邮件地址?

标签: google-apps-scriptgoogle-sheetsgoogle-drive-api

解决方案


getViewers()返回观众和评论员。您可以使用以下方式过滤列表getAccess()

const getCommenters = (file) => 
  file.getViewers().filter(user=>
    file.getAccess(user) == "COMMENT")

推荐阅读