且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UiApp:非Gmail用户的永久登录

更新时间:2023-12-04 10:51:52

这是一篇很老的文章,但是由于有解决方案,我认为***将其展示给有类似需求的人以帮助

This is a very old post but as there is a solution, I think it is better to show it to help people with a similar need

乔希,你好

我已经开发了这样的系统,确实有一种方法可以做到这一点.

I have developed such a system and there is indeed a way to do this.

您确实可以开发使用Cookie的系统,例如使用PrivateCache类:CacheService.getPrivateCache().

You can indeed develop a cookie like system that is using the PrivateCache class: CacheService.getPrivateCache().

如果用户重新加载页面或关闭页面,此功能就起作用.

It works if the user reload the page or close it.

但是,使用此解决方案,当您关闭浏览器时,将无法再检索信息.

However with this solution when you close your browser it will not be possible to retrieve the information anymore.

这是我用来防止您强调的问题的功能

Here are the functions that I use to prevent the problem you have underlined

随时适应它们

function getCookie(){
  var cache=CacheService.getPrivateCache();
  var cached=cache.get("UserCookie");
  if(cached!=null){
    return Utilities.jsonParse(cached);
  }
  return -1;
}

function createCookie(data){
  var cache=CacheService.getPrivateCache();
  cache.put("UserCookie",Utilities.jsonStringify(data),1800); 
}

function removeCookie(){
  var cache=CacheService.getPrivateCache();
  cache.remove("UserCookie"); 
}

另一种方法是使用UserProperties.在这种情况下,即使您关闭浏览器也可以使用...我刚刚尝试过

Another way would be to use UserProperties. In this case it will work even if you close your browser... I just tried it

因此要使用的功能是:

function getCookie(){
  var cached=UserProperties.getProperty('UserCookie');
  if(cached!=null){
    return Utilities.jsonParse(cached);
  }
  return -1;
}

function createCookie(data){
    UserProperties.setProperty('UserCookie',Utilities.jsonStringify(data));
}

function removeCookie(){
  UserProperties.deleteProperty("UserCookie"); 
}

我希望它将对任何人有帮助...

I hope it will help anyone...

欢呼

尼古拉斯