Reputation: 33
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);
}
});
}
Upvotes: 3
Views: 2865
Reputation: 201553
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.
Upvotes: 2