【发布时间】:2017-10-13 17:00:29
【问题描述】:
现在尝试了几个小时 - 有没有办法在已部署的 Web 应用程序中向服务器端 Google 脚本的 URL 添加参数,对任何人(不仅是 Google 帐户)开放?
我想在用户登录时存储一个密钥,这样用户就不必在每次刷新浏览器时再次登录。假设我当前的网址是: https://script.google.com/a/macros.../exec
我可以在登录时以某种方式添加 GAS 功能,以便将 URL 修改为类似 https://script.google.com/a/macros.../exec?key=abcdef&name=John%20Doe
这样,如果 doGet(e) 函数再次运行(网站重新加载)并且临时生成的密钥与我数据库中的用户名匹配,则用户将被定向到页面 B,如果密钥不匹配(或已在时间触发器上被删除)用户将被定向到页面 A(登录页面)?
我还试图找到将某些内容放入本地缓存的方法,但也无法弄清楚。Google CacheService 似乎只将密钥存储在我作为用户而不是客户端。
我想要实现的示例:
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;
}
【问题讨论】:
-
我想你可能想看看PropertyService
-
@Cooper 谢谢我会尽快尝试这个 - 一直在尝试用谷歌搜索,但无法找到 PropertiesService 和 CacheService 的比较 - 两者都有 userCache /userProperties 但是当我使用它时CacheService userCache 充当脚本(我)的执行者,因为这就是我的网络应用程序的设置方式 - 即使应用程序已部署,因此“任何人,甚至匿名”都可以访问它。也许我应该将网络应用程序设置为充当“用户访问脚本”..?
-
尝试了 PropertiesService,它甚至在 setUserProperties 上也充当 CacheService,可能是因为脚本以我自己(脚本所有者)的身份执行..
-
你试过this solution吗?
标签: javascript google-apps-script