在 Google Docs 中以编程方式创建锚定评论 [英] Creating anchored comments programmatically in Google Docs
问题描述
我无法使用包含文档的应用脚本以编程方式创建锚定到 Google 文档中特定文本的评论.
I have been unable to programmatically create a comment that is anchored to specific text in a Google Doc using an app script with the document.
有关如何使用 Google Drive API 创建锚定评论的 Google 文档:https://developers.google.com/drive/web/manage-comments
Google documentation about how to create an anchored comment using the Google Drive API: https://developers.google.com/drive/web/manage-comments
这是我必须在文档中创建评论的代码:
Here is the code I have to create the comment in the doc:
Drive.Comments.insert({
"kind": "drive#comment",
"author": {
"kind": "drive#user",
"displayName": USER_EMAIL,
"isAuthenticatedUser": true,
},
"content": CONTENT,
"status": "open",
"anchor": "{'r':"
+ REVISION_ID
+ ",'a':[{'txt':{'o':"
+ STARTING_OFFSET
+ ",'l':"
+ OFFSET_LENGTH
+ ",'ml':"
+ TOTAL_CHARS
+ "}}]}",
"fileId": FILE_ID
}, FILE_ID);
/* USER_EMAIL, CONTENT, REVISION_ID, FILE_ID: string,
STARTING_OFFSET, OFFSET_LENGTH, TOTAL_CHARS: int */
在这种情况下,我尝试为文档中与 STARTING_OFFSET
和 OFFSET_LENGTH
对应的特定字符创建文本锚点.
In this case, I am trying to create a text anchor to specific characters in the doc which correspond to the STARTING_OFFSET
and OFFSET_LENGTH
.
目前这段代码创建了一个可在 Google Docs 中访问的评论;但是,它没有锚定到文档中的任何文本,这是预期目的所必需的.
Currently this code creates a comment accessible in Google Docs; however, it is not anchored to any text in the document, which is necessary for the intended purpose.
我已确保使用当前修订版 ID(因为这可能会导致问题,如 Google 文档中所述).
I have made sure that the current revision id is used (as this could cause issues, as mentioned in the Google documentation).
非常感谢任何建议,如果有人可以发布或指出以编程方式在 Google 文档中创建锚定评论的示例,我将不胜感激.
Any suggestions are greatly appreciated and if any one could post or point to an example of creating anchored comments in Google Docs programmatically, I would be extremely grateful.
提前致谢!
推荐答案
来自 Google Drive API 的锚定评论功能适用于非 Google 文档编辑器文件,而不适用于 Google 文档.参见 https://youtu.be/ZBU52nacbLw?t=5m26s(感谢 Bryan P 分享通过评论)
The Anchoring Comments feature from the Google Drive API is intended for non-Google Docs editors files, not for Google Documents. See https://youtu.be/ZBU52nacbLw?t=5m26s (credit to Bryan P who shared this URL through a comment)
不幸的是,目前来自 Google Apps Script 的文档服务没有't 包括一个班级评论来处理评论和讨论.
Unfortunatelly at this time the Document Service from Google Apps Script doesn't include a Class Comment to handle comments and discussions.
2016 年初,通过 Google Apps 脚本问题和功能请求官方网站发布了功能请求.通过为此功能请求加注星标,您可以帮助 Google 员工关注它:
At the beginning of 2016 a feature request was posted through the Google Apps Scripts Issues and features requests official site. By starring this feature request you could help to make that Googlers put attention to it:
问题 5650:提供创建Drive API 注释锚点资源作为 DocumentApp 选择类上的方法
2012 年发布的旧参考文献,非常相似但范围更广,通过 Alexander 的评论引用:
问题 1618:提供对评论的读/写访问权限谷歌文档
An older reference, posted on 2012, very similar but broader, referred through a comment by Alexander:
Issue 1618: Provide read/write access to comments in Google Docs
参考资料
这篇关于在 Google Docs 中以编程方式创建锚定评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!