我有一个程序必须完全在App脚本中运行(使用它的用户没有安装权限计算机的插件)。该计划根据报价中的信息制作商业报价和其他一些内容。showModalDialog()即使if()门没有正在评估为真也运行
我需要复制引号以保存它们,然后授权代码在这些副本上运行,以便如果需要进行更改,它们可以是。
function onOpen(e) {
var authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);
var authStatus = authInfo.getAuthorizationStatus();
var authRequired = (authStatus == ScriptApp.AuthorizationStatus.REQUIRED);
Logger.log(authStatus);
Logger.log(authRequired);
if (authRequired) {
Logger.log('Authorization required');
var authScript = '<script type="text/javascript">'+
'function openAuthWindow() {'+
'window.open("'+authInfo.getAuthorizationUrl()+'");'+
'}'+
'</script>';
var alert = HtmlService.createHtmlOutputFromFile('sidebarHeadOpen')
.append(HtmlService.createHtmlOutput(authScript).getContent())
.append(HtmlService.createHtmlOutputFromFile('authorizeAlert').getContent());
SpreadsheetApp.getUi().showModalDialog(alert, 'Authorization Required');
} else {
var frontend = e.source;
initialize(frontend);
}
}
我的问题是内部的代号为“如果(authRequired){...}”仍在运行,即使它不应该。 (即当authStatus为NOT_REQUIRED且authRequired为false时)更重要的是,尽管日志应该在运行代码时显示“需要授权”,但它不会。从该语句运行的唯一行是“var authScript = ...;”行,“var alert = ...;”行和“SpreadsheetApp.getUi()。showModalDialog();”线。我试图让不是发生。有没有办法做到这一点?
以供参考,这是alert.html样子:
<html>
<head>
<base target="_top">
<script type="text/javascript">
function openAuthWindow() {
window.open("'+authInfo.getAuthorizationUrl()+'");
}
</script>
</head>
<body>
Please authorize this copy of the form to run.<br>
<br>
Without authorization, it will not do anything automatically.<br>
<br>
<input type="button" value="Review Permissions" onclick="google.script.host.close(); openAuthWindow(); google.script.run.runInstall();" />
</body>
</html>
(此外,有没有一个简单的提示进行授权方式甚至一个刚刚编程方式获取它,而不提示用户? )
这是一个网络应用程序? 'onOpen()'如何运行?从电子表格? –