我正在使用react google-应用程序-脚本来为电子表格实现Google脚本UI。
我的服务器实现中有代码作为
const getActiveUserEmail = () => {
return Session.getActiveUser().getEmail();
};它是通过以下方式从客户端引用的:
import { getActiveUserEmail } from '../../../server';
const email = getActiveUserEmail();在部署到电子表格并运行它之后,当代码被击中时,我会得到未定义的“会话”。如果该代码被击中,我还会得到“PropertiesService未定义”。
我能够没有问题地使用HtmlService、SpreadsheetApp和UrlFetch apis。
我的appscript.json文件包含
{
"timeZone": "America/New_York",
"dependencies": {},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": [
"https://www.googleapis.com/auth/script.container.ui",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/userinfo.email"
],
"runtimeVersion": "V8"
}为什么这些是未定义的,我如何才能强迫它们被定义?
更新: Enushi提供了一个工作代码示例。
发布于 2022-10-22 14:35:44
很可能..。
const email = Session.getActiveUser().getEmail();
const props = PropertiesService.getScriptProperties().getProperties();在客户机端代码(以某种方式传递给HtmlService.htmlOutput)中,而不是在服务器端代码中。
上述方法可以与Html.htmlTemplate一起使用,但应该包含在脚本中,以便作为服务器端代码执行。
相关
参考文献
https://stackoverflow.com/questions/74160470
复制相似问题