现在已经尝试了几个小时 - 有没有办法在已部署的网络应用程序中向服务器端 Google 脚本上的 URL 添加参数,该参数对任何人(不仅是 Google 帐户)开放?
我想存储用户登录时的 key ,以便用户不必在每次刷新浏览器时再次登录。假设我当前的网址是: https://script.google.com/a/macros.../exec
我可以以某种方式在登录时添加 GAS 函数,以便将 URL 修改为类似的内容 https://script.google.com/a/macros.../exec?key=abcdef&name=John%20Doe
这样,如果 doGet(e) 函数再次运行(网站重新加载)并且临时生成的 key 与我的数据库中的用户名匹配,则用户将被定向到页面 B,如果 key 不匹配(或已在时间触发器上删除)用户将被定向到页面 A(登录页面)?
我还尝试找到将某些内容放入本地缓存的方法,但也无法弄清楚。Google CacheService 似乎只将我作为用户而不是客户端的 key 存储起来。
我想要实现的目标示例:
function doGet(e){
var name = e.parameter.name, output;
if(name === undefined){
/*/
Add parameter name=john to URL..
obviously what I intend to is to create a HtmlOutput on a login-page
and then in a later (function login()) add this parameter there and not
here, but if anyone can work this out for me I got the solution
/*/
} else {
output = HtmlService.createHtmlOutput('Welcome back ' + name);
}
return output;
}
最佳答案
这是一个可能的解决方案,根据提供的 URL 参数将用户名保存到 PropertiesService,如果已经存在,则获取 key 。
function doGet(e) {
//use the session service to get the active users email
var currentUser = e.parameter.name;
var key = e.parameter.key;
var props = PropertiesService.getUserProperties().getProperty(currentUser);
if(props) {
//do something with the key
} else {
//if there is no username key in the properties service, then add it
PropertiesService.getUserProperties().setProperty(currentUser, key);
}
}
以下是文档:
关于javascript - 在 Google 脚本网络应用中添加 URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43970514/