2

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

Rubén
  • 34,714
  • 9
  • 70
  • 166
Sanjay
  • 8,755
  • 7
  • 46
  • 62
  • Related: [Creating anchored comments programmatically in Google Docs](http://stackoverflow.com/questions/23498275/creating-anchored-comments-programmatically-in-google-docs) – Rubén Jun 29 '16 at 19:59

2 Answers2

8

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
Nigini
  • 454
  • 1
  • 5
  • 16
  • is there a way to get the actual content of google doc programmatically? thank you I posted a question about that here https://stackoverflow.com/questions/58359501/accessing-google-document-programmatically thank you – Kamel Labiad Oct 12 '19 at 23:50
0

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.

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51
  • 2
    Thanks for the info. Filed a [feature request](http://code.google.com/p/google-apps-script-issues/issues/detail?id=1618). – Sanjay Jul 26 '12 at 04:58
  • At this time it's possible to access the document's comments. See the [answer](http://stackoverflow.com/a/35494863/1595451) by [Nigini](http://stackoverflow.com/users/539223/nigini) – Rubén Jun 29 '16 at 20:01