我在Google文档中使用以下代码插入文字。但它不起作用。 Google也没有在JavaScript中为batchupdate提供任何单个示例。有人知道那件事吗?
function makeApiCall() {
var updateObject = {
documentId: 'My-Document-Id',
resource: {
requests: [{
"insertText": {
"text": "Sameer Bayani",
"location": {
"index": 25,
},
},
}],
},
};
gapi.client.docs.documents.batchUpdate(updateObject, function (e, r) {
if (e) {
console.log(e);
} else {
console.log(r.data);
}
});
}
这个修改怎么样?
1
作为index
的location
作为测试。在这种情况下,文本也可以插入到新文档中。因为我认为使用25
时可能会发生错误。function (e, r) {if (e) {console.log(e);} else {console.log(r.data);}}
脚本是针对Node.js的googleapis。所以我把它修改为Javascript。
关于Its Not Work.
,我认为原因可能是这个。因为在您的脚本中,不会返回任何响应。function makeApiCall() {
var updateObject = {
documentId: 'My-Document-Id',
resource: {
requests: [{
insertText: {
text: "Sameer Bayani",
location: {
index: 1, // Modified
},
},
}],
},
};
gapi.client.docs.documents.batchUpdate(updateObject)
.then(function(res) { // Modified
console.log(res);
},function(err) {
console.error(err);
});
}
https://www.googleapis.com/auth/documents
作为范围。如果我误解了你的问题,我道歉。