如何在谷歌文档中获取评论的受让人?

问题描述 投票:0回答:1

官方文档中似乎没有提及获取(或设置)谷歌文档中评论的受让人的方法。

是否有任何已知的方法,包括一些聪明的解决方法,以允许获取/推断 gdoc 中评论的受让人的姓名和/或电子邮件?

google-apps-script google-drive-api google-docs-api
1个回答
1
投票

解决方法:使用 Drive API v2

此解决方法列出了所有评论以及作者和受让人。但是,假设第一个“@email”将是受让人,因为目前 Drive API 中没有用于列出评论受让人的特定字段。

剧本

您可以使用下面的脚本作为创建您的脚本的基础。另外,请在服务选项卡中包含

Drive API v2

function getAssignee() {
  var fields = Drive.Comments.list("FILE ID",{ fields: "*" }); //Insert file ID here
  var commentsQty = fields.items.length;
  for (let i = 0; i <commentsQty; i++) {
    var commentAuthor = fields.items[i].author.displayName; //gets the comment author
    var contentValue = fields.items[i].content; //gets the comment content
    var commentResolve = fields.items[i].resolved; //Checks if the comment is resolved
    var assignee = contentValue.match(/@[^\s]+/g); //extract the assignee assuming that the first @emailaddress is the assignee
    console.log("Comment Author: ",commentAuthor,"\nAssignee:",assignee[0],"\nStatus:",commentResolve?"Resolved":"Not Yet Resolved","\nComment: ",contentValue)
  }
}

输出:

参考资料:

© www.soinside.com 2019 - 2024. All rights reserved.