I want to add some text to user’s google docs document. We have id of document and oauth token of user with permission. But text need to be inserted at exactly on cursor position not at end or beginning of document.
const doc = DocumentApp.getActiveDocument();
const cursor = doc.getCursor();
This works but if I deploy it via API Executable and then make an api call with user oauth access token( we already have it) and I want to run it on all documents of user of google docs. it doesn’t work anymore. We do have id of document and if open by id getCursor doesn’t work. Somehow it should be possible to insert text at cursor position in any document.
Please note we want to run it through a call and not add in button
Some methods, like DocumentApp.Document.getCursor()
only work as expected when the Apps Script function is called from the Google Docs Editor user interface or the Apps Script Editor. The latter only works when the Apps Script project is opened by clicking Extensions > Apps Script.
It would be best if you changed the design of your solution first to get somehow the position for the text to insert. You might use a bookmark, a named range, and find text, among other options.
1