- 您想使用 Docs API 删除 Google Document 中的所有内容。
如果我的理解是正确的,那么这个答案呢?请认为这只是几个可能的答案之一。
问题:
在当前阶段,为了使用“DeleteContentRangeRequest”,startIndex 和endIndex 的值都是必需的。这似乎是规范。所以在你的情况下,我认为is it possible to get the endIndex somehow, or delete all content another way? 会导致解决你的问题的方法。
解决方法流程:
这里,作为解决方法,使用以下流程。
1。从 Google 文档中检索 content 的对象。
示例 curl 命令如下。当您使用它时,请设置文档 ID。在这种情况下,body.content(startIndex,endIndex) 用作字段。这样就很容易看到响应值了。
curl \
'https://docs.googleapis.com/v1/documents/###?fields=body.content(startIndex%2CendIndex)' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json'
响应值如下。
{
"body": {
"content": [
{"endIndex": 1},
{"startIndex": 1, "endIndex": 100},
{"startIndex": 100, "endIndex": 200}
]
}
}
-
content 的最后一个索引中的 endIndex 就是这个值。
2。从对象中检索endIndex。
从上面的响应值可以看出startIndex和endIndex分别是1和199。如果endIndex 是200,则会发生错误。请注意这一点。所以请减少1。
3。使用startIndex和endIndex删除所有内容。
curl 命令示例如下。
curl --request POST \
'https://docs.googleapis.com/v1/documents/###:batchUpdate' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"requests":[{"deleteContentRange":{"range":{"startIndex":1,"endIndex":199}}}]}'
参考资料:
如果我误解了您的问题并且这不是您想要的方向,我深表歉意。