I got the below script for automatic "last edited" timestamp in the
footer of a Google Document.
function lastEdited() {
var doc = DocumentApp.getActiveDocument();
var id = doc.getId();
var file = Drive.Files.get(id);
var footerSection = (doc.getFooter())?doc.getFooter():doc.addFooter();
footerSection.clear();
var userName = file.lastModifyingUserName;
var date = file.modifiedDate;
var text = '[Last edited by ' + userName + ' on ' + Utilities.formatDate(new Date(date), 'GMT+5', 'YYYY/MM/dd hh:mm') + ']';
var p = footerSection.insertParagraph(0,text);
p.setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
}
But there is below mentioned error in this
SyntaxError: Unexpected token ':' (line 4, file "Code.gs")
Can anyone help me in this?
Best Answer
You need to enable the Drive API in the advanced Google service first:
From the script editor go to Resources > Advanced Google service and turn the Drive API on. Onces you've done that, you need to press the bug button to authenticate the script again.