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