访问Google文档中的注释

San*_*jay 2 google-docs google-apps-script

我无法弄清楚如何使用Google Apps脚本访问Google文档中的注释。查看API参考,我仅找到CommentSection类,但已将其标记为已弃用。寻求帮助。谢谢。

桑杰

Nig*_*ini 6

经过本文的初步讨论,我已经成功使用Drive API v2在文档中获取注释。

这是我正在使用的代码:

function retrieveComments(fileId) {
  var info = [];
  //These arguments are optional
  var callArguments = {'maxResults': 100, 'fields': 'items(commentId,content,context/value,fileId),nextPageToken'}
  var docComments, pageToken;
  do { //Get all the pages of comments in case the doc has more than 100
    callArguments['pageToken'] = pageToken;
    //This is where the magic happens!
    docComments = Drive.Comments.list(fileId,callArguments);
    //I've created a "getCommentsInfo" to organize the relevant info in an array
    info = info.concat(getCommentsInfo(docComments.items));
    pageToken = docComments.nextPageToken;
  } while(pageToken);

  return(info);
}
Run Code Online (Sandbox Code Playgroud)

但是,由于Drive API是“高级服务”,因此必须将它们都添加到:

  1. 脚本项目 -通过使用“资源>高级Google服务”
  2. Google Developers Console-通过:
    1. 确保在顶部栏中选择正确的项目
    2. 为项目启用“ Drive API”