0

I copy pasted from the google api and in my code I verify the user using a token and then right after that I do this code

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()

but I keep getting an error code that says

    "Invalid requests[0].insertText: Index 25 must be less than the end index of the referenced segment, 2.

1 Answer 1

1

The error message is telling you that the segment you are trying to insert text into is only two characters long, and that you can't insert anything at index 25, because a string two characters long only has indexes 0 and 1. If you change the index to 0 or 1, it should work (at least for the first request).

Start and End Index explained in the Docs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.