【问题标题】:How to/where to add the insert text function in Google docs API如何/在何处在 Google docs API 中添加插入文本功能
【发布时间】:2020-11-13 14:29:45
【问题描述】:

我从 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.

【问题讨论】:

    标签: python google-api google-docs-api


    【解决方案1】:

    错误消息告诉您,您尝试插入文本的段只有两个字符长,并且您不能在索引 25 处插入任何内容,因为两个字符长的字符串只有索引 0 和 1。如果将索引更改为 0 或 1,它应该可以工作(至少对于第一个请求)。

    Start and End Index explained in the Docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多