我想定期备份在 Google 电子表格上编码的项目(默认 GCP 项目)。最重要的是它是原始电子表格的副本。所以项目脚本文件绑定到电子表格。
Bound scripts generally behave like standalone scripts except that they do not appear in Google Drive来自上述文档链接的引用。
我想这就是我收到错误的原因
Error GoogleJsonResponseException: API call to drive.files.get failed with error: File not found:
12OX6dRqsEHRsR4MttkDQ71yW_I8R2UqjfcSq4FB backupSS @ web functions.gs:3958
在下面代码的第 4 行。请注意,scriptId 存在但文件不可访问
var spreadSheetId = SpreadsheetApp.getActiveSpreadsheet().getId()
var scriptId = ScriptApp.getScriptId()
console.log(Drive.Files.get(spreadSheetId))
console.log(Drive.Files.get(scriptId))
有了这个结果
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`
有没有办法以编程方式编辑脚本名称?为什么我没有很多同名的脚本。
更新
Google Apps 脚本 API 已启用
请求的身份验证范围不足。
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) }};
给我
Response content: {
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"status": "PERMISSION_DENIED"
}
}

