python - 如何/在何处在 Google docs API 中添加插入文本功能
问题描述
我从google api复制粘贴并在我的代码中使用令牌验证用户,然后立即执行此代码
text1="text"
text2="bruh"
text3="reee"
requests = [
{
'insertText': {
'location': {
'index': 25,
},
'text': text1
}
},
{
'insertText': {
'location': {
'index': 50,
},
'text': text2
}
},
{
'insertText': {
'location': {
'index': 75,
},
'text': text3
}
},
]
result = service.documents().batchUpdate(
documentId=DOCUMENT_ID, body={'requests': requests}).execute()
但我不断收到一个错误代码,上面写着
"Invalid requests[0].insertText: Index 25 must be less than the end index of the referenced segment, 2.
解决方案
错误消息告诉您,您尝试插入文本的段只有两个字符长,并且您不能在索引 25 处插入任何内容,因为两个字符长的字符串只有索引 0 和 1。如果您更改索引为 0 或 1,它应该可以工作(至少对于第一个请求)。
推荐阅读
- python - 如何在命令提示符中将 \r\n 显示为实际的换行符?
- laravel - 添加新组时如何打开链接?拉拉维尔
- angular - 表单数组所有控件条件需要验证
- asp.net-mvc - 如何在asp.net中使列表项可点击
- python - 将 Plotly-Dash 与 Tkinter GUI 相结合 - Dash 强制再次执行 Tk-mainloop
- web - 什么是最简单的 Windows 邮件服务器,仅用于发送邮件。邮件服务器?
- flutter - 在 MobX 依赖项的空安全版本上运行 build_runner 时出错
- r - “替换有 2 行,数据有 114591”,带有 foreach 和 doparallel
- javascript - 从移动设备上的 LinkedIn 中的链接查看时,为什么我的 h1 文本跟随垂直页面滚动?
- javascript - 拖放后更新数据库