问题
Given a google doc retrieved through the Google docs API and its comments retrived with the Drive API,
How do you know where in the document a comment corresponds?
I've been inspecting all the fields and couldn't find a relation except the quotedFileContent
that contains the commented text in the doc, but this would resolve ambiguously if that text is duplicated.
回答1:
You cannot retrieve the location of a comment using Drive API.
As you can see in the official documentation, the Comment resource has an anchor
field that provides information on the region of the document. Nevertheless, if you use the API to get information about a comment, you will see that the anchor
field in the response is actually a string identifier composed of a kix
prefix and a certain anchor ID as a suffix, which don't really give you an idea of where the comment is located.
The problem is not just about retrieving the locations to which a comment is anchored, but also about creating anchored comments in a desired location using the API, as you can see here.
Basically, as it is currently implemented, this anchor
tool is meant for third-party integrations to use this API to specify their own custom anchor data.
There are several open cases in Issue Tracker related to this:
- https://issuetracker.google.com/issues/36756056
- https://issuetracker.google.com/issues/36763384
Reference:
- https://developers.google.com/drive/api/v3/manage-comments
- https://www.youtube.com/watch?v=ZBU52nacbLw
来源:https://stackoverflow.com/questions/58983822/location-of-a-comment-in-its-corresponding-google-doc