google-apps-script - Google Doc 评论 - 使用 Appscript 更新
问题描述
我希望每个人都身体健康。我是AppScript的新手,喜欢使用它自动化 Google Docs 的概念。
我尝试了什么;
我最近遇到了一个问题,我需要使用 AppScript 根据其在 Google Docs 中的评论来更新文本。
这是演示 ,但我知道使用 AppScript 是不可能的,所以我必须使用Google Drive API并且我尝试了它,但我仍然没有成功。当我尝试时,它似乎确实发生了变化,console.log(comments.items[i].context.value);
但我的 Google Doc 中的一切都是一样的,似乎没有任何改变。
这是我的代码;
function listComments() {
let comments = Drive.Comments.list(DocumentApp.getActiveDocument().getId());
if (comments.items && comments.items.length > 0) {
for (let i = 1; i < comments.items.length; i++) {
let comment = comments.items[i].content;
let text = comments.items[i].context.value;
comments.items[i].context.setValue(`[${text}](${comment})`);
console.log(comments.items[i].context.value);
}
} else {
Logger.log('No comment found.');
}
}
我在任何地方都找不到更新AppScript 中的评论上下文值的文档,这也将反映在我的 Google Doc 中。
我希望你能解决我的问题。提前致谢!
解决方案
检查 Drive API 后,我没有找到任何方法来更新评论的 context.value 属性。更新评论时,您需要使用Comments.update()。但是,此方法仅允许您修改/更新评论的内容。如果您尝试根据评论内容替换 Google Docs 中的特定字符串,您需要使用Apps Script中的Document Service更新文档
更新现有评论时,您需要提供以下参数:
commentId - 评论的 ID。
fileId - 文件的 ID。
commentId 在 Comments.list 响应中可用
样本:
{
"kind": "drive#comment",
"commentId": "sampleCommentId",
....
},
"htmlContent": "Test Name",
"content": "Test Name",
"deleted": false,
"status": "resolved",
"context": {
"type": "text/html",
"value": "name"
},
例子:
内容 = "测试名称"
context.value = "名称"
如果我将使用带有以下请求正文的Comments.update()更新此评论:
{
"content": "My Name",
"context": {
"value": "name"
}
}
输出:
推荐阅读
- php - 使用外键上传图片
- swift - 使用 ShouldPerformSegue 取消在情节提要中创建的转场
- ios - 重用单个 SKView 生成多个 SKTexture 以供在 SceneKit 中使用
- object - 在java中从Object类型数据转换为int类型数据
- c - 来自命令行的有效负载不会覆盖堆栈
- c# - 如何从包含字符串数组的 JSON 中选择值?
- pandas - groupby的平均值,在变量上切割后
- php - Symfony 3.14 createForm 构建器未定义方法添加
- javascript - 无法使用nodejs启动js文件
- javascript - Webpack copyFiles将文件从子目录复制到主目录