1

I have a Google Sheet file with >100 comments and I'm looking to extract them using App Script. My code works to pull the first 99, which I'm able to then manipulate as needed. However, I am struggling to get the all comments using the nextPageToken. Hoping someone can help me implement this into the code below.

I've reviewed a few examples related to Drive.Files.list to no avail - have not seen an example for Drive.Comments.list.

function getComments(fileId) {
  var options = {
    'maxResults': 99
  };

  var comments =  Drive.Comments.list(fileId, options);

  return comments;
}

I currently get 99 results. I want to get all results even if there are >100 comments.

Edit Here's how I ended up modifying the code to achieve the desired result.

function getComments(fileId) {
  var pageToken = "";
  var items = [];
  while (typeof pageToken !== "undefined") {
    var options = {
    'maxResults': 99,
    'pageToken': pageToken
  };
  var comments =  JSON.parse(Drive.Comments.list(fileId, options));
  var pageToken = comments.nextPageToken;
  items.push(comments.items);
  }
  return items;
}
  • Is this answer useful for your situation? https://stackoverflow.com/a/35494863 – Tanaike Oct 19 '19 at 21:53
  • It is - thank you. I was able to modify my function as follows to achieve what I was looking for: `function getComments(fileId) { var pageToken = ""; var items = []; while (typeof pageToken !== "undefined") { var options = { 'maxResults': 99, 'pageToken': pageToken }; var comments = JSON.parse(Drive.Comments.list(fileId, options)); var pageToken = comments.nextPageToken; items.push(comments.items); } return items; }` – crazyitalian1988 Oct 20 '19 at 17:57
  • Thank you for replying. I'm glad your issue was resolved. – Tanaike Oct 21 '19 at 01:31

0 Answers0