I want to make a regular backup of a project (default GCP project) that is coded on top of Google Spreadsheet. And on top of the it is a COPY of original SpreadSheet. So the project script file is bound to the spreadsheet.
Bound scripts generally behave like standalone scripts except that they do not appear in Google Drive
a quote from above documentation link.
I guess that is the reason why I get an error
Error GoogleJsonResponseException: API call to drive.files.get failed with error: File not found:
12OX6dRqsEHRsR4MttkDQ71yW_I8R2UqjfcSq4FB backupSS @ web functions.gs:3958
on the 4th line of below code. Note that the scriptId exists but the file is not accessable
var spreadSheetId = SpreadsheetApp.getActiveSpreadsheet().getId()
var scriptId = ScriptApp.getScriptId()
console.log(Drive.Files.get(spreadSheetId))
console.log(Drive.Files.get(scriptId))
with this result
9:24:12 PM Notice Execution started
9:24:12 PM Info PR-Digitalizace objednávek
9:24:12 PM Error GoogleJsonResponseException: API call to drive.files.get failed with error: File not found: 12OX6dRPKwwt1-vOtCsbDEHRsR4MttkDQ71yW_I8R2Uqq4FB
backupSS @ web functions.gs:3958
console.log(DriveApp.getFileById(scriptId).getName()) givess me this error `Error
Exception: No item with the given ID could be found. Possibly because you have not edited this item or you do not have permission to access it.
backupSS @ web functions.gs:3959`
is there any way to edit scritp name programatically? Why so I do not have lots of script with the same name.
Update
Google Apps Script API is on
Request had insufficient authentication scopes.
function getScriptContent(scriptId,content,theAccessTkn) { try{ var options,payload,response,url;
if (!scriptId) { scriptId = ScriptApp.getScriptId() } if (!content) { //Error handling function console.log("no content") } if (!theAccessTkn) { theAccessTkn = ScriptApp.getOAuthToken(); } //https://developers.google.com/apps-script/api/reference/rest/v1/projects/updateContent url = "https://script.googleapis.com/v1/projects/" + scriptId +"content" url = "https://scriptmanagement.googleapis.com/v1/projects/" + scriptId //+"content" options = { "method" : "GET", "muteHttpExceptions": true, "headers": { 'Authorization': 'Bearer ' + theAccessTkn }, "contentType": "application/json",//If the content type is set then you can stringify the payload // "payload": JSON.stringify(content) }; response = UrlFetchApp.fetch(url,options); console.log('getResponseCode ' + response.getResponseCode()) console.log("Response content: " + response.getContentText()) console.log("finished " ) } catch(e) { console.log("Error: " + e + "\nStack: " + e.stack) }
};
gives me
Response content: {
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"status": "PERMISSION_DENIED"
}
}