问题
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:
- Script Project - by using the "Resources > Advanced Google Service"
- Google Developers Console - by:
- Making sure to select the right project in the top bar
- Enabling the "Drive API" for the Project
来源:https://stackoverflow.com/questions/11630812/accessing-comments-in-google-documents