I have Use Following Code For Insert Text In Google Docs. But Its Not Work. Google Also Not provided any single example in JavaScript for batchupdate. anyone knows about that thing?
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);
}
});
}
How about this modification?
1 as index of location as a test. In this case, the text can be also inserted to new Document. Because I thought that when 25 is used, an error might occur.function (e, r) {if (e) {console.log(e);} else {console.log(r.data);}} is for googleapis of Node.js. So I modified this to Javascript.
Its Not Work., I thought that the reason might be this. Because in your script, no response is returned.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 as the scope.If I misunderstood your question, I apologize.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With