首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么会话和PropertiesService在使用react时没有定义-google-apps script

为什么会话和PropertiesService在使用react时没有定义-google-apps script
EN

Stack Overflow用户
提问于 2022-10-22 01:18:48
回答 1查看 37关注 0票数 0

我正在使用react google-应用程序-脚本来为电子表格实现Google脚本UI。

我的服务器实现中有代码作为

代码语言:javascript
复制
const getActiveUserEmail = () => {
  return Session.getActiveUser().getEmail();
};

它是通过以下方式从客户端引用的:

代码语言:javascript
复制
import { getActiveUserEmail } from '../../../server';
const email = getActiveUserEmail();

在部署到电子表格并运行它之后,当代码被击中时,我会得到未定义的“会话”。如果该代码被击中,我还会得到“PropertiesService未定义”。

我能够没有问题地使用HtmlService、SpreadsheetApp和UrlFetch apis。

我的appscript.json文件包含

代码语言:javascript
复制
{
  "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提供了一个工作代码示例

EN

回答 1

Stack Overflow用户

发布于 2022-10-22 14:35:44

很可能..。

代码语言:javascript
复制
const email = Session.getActiveUser().getEmail();
const props = PropertiesService.getScriptProperties().getProperties();

在客户机端代码(以某种方式传递给HtmlService.htmlOutput)中,而不是在服务器端代码中。

上述方法可以与Html.htmlTemplate一起使用,但应该包含在脚本中,以便作为服务器端代码执行。

相关

参考文献

  • http://developers.google.com/apps-script/guides/html
  • http://developers.google.com/apps-script/guides/html/templates
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74160470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档