Skip to content Skip to sidebar Skip to footer

How To Google "docs" Api Batchupdate In Javascript (code Required)

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

Solution 1:

How about this modification?

Modification points:

  • I think that your request body is correct.
    • But I used 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.
  • I think that your script of 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.
    • About Its Not Work., I thought that the reason might be this. Because in your script, no response is returned.

Modified script:

functionmakeApiCall() {
  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) { // Modifiedconsole.log(res);
  },function(err) {
    console.error(err);
  });
}

Note:

  • This modified script supposes that you have already used Google Docs API by Javascript. When the authorization of your script works, above modified script works. If the errors related to authorization and Docs API occur, please confirm about the script and whether Docs API is enabled.
  • In order to test this script, I used https://www.googleapis.com/auth/documents as the scope.

Reference:

If I misunderstood your question, I apologize.

Post a Comment for "How To Google "docs" Api Batchupdate In Javascript (code Required)"