替代已弃用的UiApp和UiInstance [英] replacement for deprecated UiApp and UiInstance

查看:97
本文介绍了替代已弃用的UiApp和UiInstance的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想说的是,我与编码领域的知识渊博的人相距甚远,而我恰好是对此主题最了解的人,因此是我寻求帮助的原因.

To start off I would like to say I am nowhere near a knowledgeable person in coding and I just happen to be the person with most knowledge regarding this subject hence the reason why I get to look for help.

前一段时间,我弗兰肯斯坦(Frankenstein)一起制作了一个Google脚本,在页面上放置时间戳,以显示上次修订日期和发布日期.但是,最近我在两行中注意到已弃用"消息.为了使当前脚本正常工作,我付出了很多努力,因此我在这里提供一些指导.

A while back I Frankensteined together a google script to put a time stamp on a page that would show last revision date and published date. However, recently I've noticed a "Deprecated" message on two lines. I struggled quite a bit to make the current script work so I'm here for some guidance.

function doGet(e){
  var app= UiApp.createApplication();
  var page = SitesApp.getActivePage();
  var updated = Utilities.formatDate(page.getLastUpdated(), "America/Chicago", "EEE, d MMM yyyy, hh:mm:ss a '('z')'");
  var published = Utilities.formatDate(page.getDatePublished(), "America/Chicago", "EEE, d MMM yyyy, hh:mm:ss a '('z')'");
  app.add(app.createHTML('Last revision: ' + updated));
  app.add(app.createHTML('Published: ' + published));
  return app;
}

这是当前代码,这是我收到的错误消息

This is the current code and here is the error message I'm getting

已弃用UiApp API.
文件:代码行:2
该API已被标记为已弃用,这意味着应避免使用该功能,将来可能会删除该功能.考虑使用替代解决方案.

UiApp API is deprecated.
File: Code Line: 2
The API has been marked as deprecated which means that the feature should be avoided and may be removed in the future. Consider using an alternative solution.

已弃用UiInstance API.
文件:代码行:6
该API已被标记为已弃用,这意味着应避免使用该功能,将来可能会删除该功能.考虑使用替代解决方案.

UiInstance API is deprecated.
File: Code Line: 6
The API has been marked as deprecated which means that the feature should be avoided and may be removed in the future. Consider using an alternative solution.

任何帮助或指导将不胜感激.我将继续做一些研究,希望能更好地了解这个已弃用的API

Any help or guidance would be greatly appreciated. I will keep on doing some research on my side to hopefully better understand this deprecated APIs

推荐答案

仔细阅读 https://developers.google.com/apps-script/reference/ui/ui-instance

After some perusing of https://developers.google.com/apps-script/reference/ui/ui-instance and https://developers.google.com/apps-script/reference/html/html-service it would seem like this is the way to do it. This is untested code.

function doGet(e){
  var app= HtmlService.createHtmlOutput();
  var page = SitesApp.getActivePage();
  var updated = Utilities.formatDate(page.getLastUpdated(), "America/Chicago", "EEE, d MMM yyyy, hh:mm:ss a '('z')'");
  var published = Utilities.formatDate(page.getDatePublished(), "America/Chicago", "EEE, d MMM yyyy, hh:mm:ss a '('z')'");
  app.append('Last revision: ' + updated);
  app.append('Published: ' + published);
  return app;
}

这篇关于替代已弃用的UiApp和UiInstance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆