How do I add a comment to a Google Doc with Google

2019-05-10 22:08发布

问题:

I was looking at the documentation and found no way to add a comment using Google Apps Script.

After scrolling a bit, I found out that the addComment() function was deprecated.

Is there currently any way to add a comment to a Google Doc using GAS (without using a deprecated script)?

回答1:

You can add comments using the Advanced Drive Service (That must be enabled before use. In the Script Editor select Resources > Advanced Google services... and then enable it in the Google Developers Console.)

Once enabled you can create a comment using Comments: insert.

Here's an example:

function myFunction(){
  var fileId = '{YOUR_DOCUMENT_ID}';
  var resource = {'content': 'Le comment'};

  Drive.Comments.insert(resource, fileId)
}

Then you can verify the comment in the Comments section of your doc: