So I'm having trouble inserting an anchored comment on a rectangular region of a PDF file using Google Apps Script. I thought I wrote the code completely correct, yet every time I ran the code (below), the comment would come out as unanchored.
I want to know now if my conclusion is correct. It seems to me the issue is that I'm using apps script and apps script uses drive v2. And perhaps I need drive v3 to make my comment.
Compare the documentation for v2 vs v3: https://developers.google.com/drive/api/v2/reference/comments/insert https://developers.google.com/drive/api/v3/reference/comments/create
Looking at the request body table in v2, the comment resource is expected to contain content, and optionally content.type and content.value
Looking at the request body table in v3, the comment resource is expected to contain content, and optionally quotedFileContent.value and anchor
Emphasis on anchor being in v3, not v2.
Does that mean drive v2 absolutely does not support anchored comments? (even though other documentation seems to suggest it does, namely: https://developers.google.com/drive/api/v2/reference/comments/get). Is the documentation self-contradictory, or am I just doing a really bad job of reading documentation?
If I do need v3, exactly how do I get it. I can't find any clear instructions on how to use v3 instead of v2.
Anyway, here's my code:
function myFunction(driveAppFolder) {
let files = driveAppFolder.getFiles()
while (files.hasNext()){
let fileId = files.next().getId()
let comment = {'content':'Comment Test',
'anchor':JSON.stringify({
'r': 'head',
'a': [
{
'rect':
{
'x': 20,
'y': 20,
'w': 30,
'h': 30,
}
}]
})
};
Drive.Comments.insert(comment, fileId);
}
}