亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法通過 Docs API 將文本添加到新的 Google Doc

無法通過 Docs API 將文本添加到新的 Google Doc

隔江千里 2023-05-10 13:28:45
我的程序正在創建文檔,每個文檔都有需要放入其中的文本。任何調用 的嘗試都會InsertTextRequest引發錯誤。List<Request> requests = new ArrayList<>();requests.add(new Request().setInsertText(new InsertTextRequest()                .setText("Simple test.")                .setLocation(new Location().setIndex(0))));BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest()                .setRequests(requests);BatchUpdateDocumentResponse response = docService.documents()                .batchUpdate(file.getId(), body).execute();Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request{  "code" : 400,  "errors" : [ {    "domain" : "global",    "message" : "Invalid requests[0].insertText: The insertion index must be inside the bounds of an existing paragraph. You can still create new paragraphs by inserting newlines.",    "reason" : "badRequest"  } ],  "message" : "Invalid requests[0].insertText: The insertion index must be inside the bounds of an existing paragraph. You can still create new paragraphs by inserting newlines.",  "status" : "INVALID_ARGUMENT"}即使嘗試在添加文本之前添加換行符也無法解決此問題。List<Request> requests = new ArrayList<>();requests.add(new Request().setInsertText(new InsertTextRequest()                .setText("\n")                .setLocation(new Location().setIndex(0))));requests.add(new Request().setInsertText(new InsertTextRequest()                .setText("Simple test.")                .setLocation(new Location().setIndex(0))));BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest()                .setRequests(requests);BatchUpdateDocumentResponse response = docService.documents()                .batchUpdate(file.getId(), body).execute();這也會調用相同的錯誤。如何正確添加文本?
查看完整描述

1 回答

?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

將對象的索引設置Location為 1,因為它是從 1 開始索引的。



查看完整回答
反對 回復 2023-05-10
  • 1 回答
  • 0 關注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號