The goal is whenever a new version was created, an auto-trigger function will get this spreadsheet's latest history version date and set it to the target cell.
I use onEdit function to trigger it.
The code is like this:
function listRevisions(fileId) { var revisions = Drive.Revisions.list(fileId) if (revisions.items && revisions.items.length > 0) { var latestVersion = revisions.items[revisions.items.length - 1] var date = new Date(latestVersion.modifiedDate) Logger.log('Date: %s, File size (bytes): %s', date.toLocaleString(), latestVersion.fileSize); return date.toLocaleString() } else { Logger.log('No revisions found.') return } } function onEdit(e){ if(e.source.getActiveSheet().getName()==="targetSheetName"){ var dateString = listRevisions(SpreadsheetApp.getActiveSpreadsheet().getId()) targetSheet.getRange(1,7,1,1).setValue(dateString ) } }
I can manually run listRevisions function and its fine with me,the problem is when I excute the listRevisions function by onEdit.It always give me a error text like
"GoogleJsonResponseException: API call to drive.revisions.list failed with error: Login Required at listRevisions"
Since I am not quite familier with google api stuff,could someone kindly help me figure out how to solove this problem?
https://stackoverflow.com/questions/65881431/how-to-solove-login-required-problem-when-using-google-sheet-script January 25, 2021 at 04:43PM
没有评论:
发表评论