0

So I'm trying to programmatically insert anchored comments on all the pdf files in a folder.

I read the following doc: https://developers.google.com/drive/api/v3/manage-comments#anchor I tried following the instructions to creating an anchored comment on a rectangular region. But whenever I do, it appears as an unanchored comment only. Any idea on what I'm doing wrong?

Here's my code:

function insertComment(driveAppFolderObject) {
  let files = driveAppFolderObject.getFiles()
    while (files.hasNext()){
      let fileId = files.next().getId()
      let comment = {'content':'Comment Testing',
      'anchor':{
        'r': 'head',
        'a': [
          {
            'rect':
            {
              'x': 20,
              'y': 20,
              'w': 10,
              'h': 10,
            }
          }]
        }
      };
      Drive.Comments.insert(comment, fileId);
    }
}
  • Does this answer your question? [Google Drive API ignores anchor parameter when creating comments in a spreadsheet](https://stackoverflow.com/questions/57511838/google-drive-api-ignores-anchor-parameter-when-creating-comments-in-a-spreadshee) – Kos Dec 11 '21 at 14:05
  • Not really. I am not trying to comment on a spreadsheet, I am trying to comment on a pdf. And I'm not sure what "you need to create your own app to process those comments" means or if it would be helpful for my situation. – Baron McDonald Dec 11 '21 at 14:22
  • Try get comment that you added and you will see – Kos Dec 11 '21 at 14:26
  • By the way, Apps Script `Drive` uses API `v2`, and documentation link you posted is `v3` – Kos Dec 11 '21 at 15:05
  • Thanks, but the v2 says the same thing: https://developers.google.com/drive/api/v2/manage-comments – Baron McDonald Dec 11 '21 at 16:30
  • Wait, nevermind, I get it. v2 does not have anchor as an optional parameter, v3 does. Sorry if I sound totall inexperienced, but how can I use v3? – Baron McDonald Dec 11 '21 at 16:37
  • > `As mentioned earlier, the JSON anchor string contains a revisionID (r) and region (a) [..]` I think it means `anchor` parameter should be a string, not object, see also https://stackoverflow.com/questions/23498275/creating-anchored-comments-programmatically-in-google-docs – Kos Dec 11 '21 at 16:40
  • I just did JSON.stringify() on the anchor parameter, and the code continued to behave in the same way. – Baron McDonald Dec 11 '21 at 16:56
  • Does this answer your question? [Will using Drive v3 allow me to insert anchored comments on pdf files?](https://stackoverflow.com/questions/70319140/will-using-drive-v3-allow-me-to-insert-anchored-comments-on-pdf-files) – ziganotschka Dec 13 '21 at 09:10

0 Answers0