Accessing comments in Google Documents

若如初见. 提交于 2021-02-08 05:28:59

问题


I am being unable to figure out how to access comments in Google documents using Google Apps Scripts. Looking at the API reference, I found only the CommentSection class, but that is marked deprecated. Looking for some help. Thanks.

Sanjay


回答1:


Unfortunately it's not currently possible to access the document's comments using Google Apps Script. You can file a feature request for this on the issue tracker.




回答2:


Following the initial discussion in this post I've managed to get the comments in a document by using the v2 of Drive API.

Here is the code I'm using:

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);
}

But, as the Drive API is an "Advance Service" you must add it both to:

  1. Script Project - by using the "Resources > Advanced Google Service"
  2. Google Developers Console - by:
    1. Making sure to select the right project in the top bar
    2. Enabling the "Drive API" for the Project


来源:https://stackoverflow.com/questions/11630812/accessing-comments-in-google-documents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!