google-apps-script - Google App 脚本 - 为什么 getTemporaryActiveUserKey() 为唯一用户返回相同的值

标签 google-apps-script

我使用 Google 应用程序脚本创建了一个联系人类型表单,并将其发布为网络应用程序。

由于我需要确定填写表单的用户是唯一的,因此我使用了 getTemporaryActiveUserKey()函数获取用户唯一的 key 并将其与其余表单数据一起保存到电子表格中。

但是,现在在许多情况下,脚本为多个不同的用户返回相同的 key 。我知道事实上这些用户使用不同的浏览器并且位于完全不同的位置。

我的问题是,这怎么可能?

下面是 code.gs 中的函数,该函数在提交表单时运行,用于检索该值

function postFormDataToSheet(form){
  var responseSheet = SSDoc.getSheetByName("Results");

  var time = new Date()

  var userKey = Session.getTemporaryActiveUserKey();
  var resultRow = [time,form.user_name, form.user_email, form.sheet,userKey]
  responseSheet.appendRow(resultRow);
}

表单 HTML 中的 JavaScript 函数在按下提交按钮时调用上述函数

$(function(){
  $('#submitButton').on('click', function(){
    google.script.run.withSuccessHandler(SuccessPage).postFormDataToSheet(this.form);    
  })
})

Web应用程序使用以下设置发布

Execute the app as: Me (myemailaddress)

Who has access to the app: Anyone, even anonymous

最佳答案

经过大量研究和尝试各种场景后,我确定了以下内容:

  • getTemporaryActiveUserKey()函数将返回一个唯一的 任何使用 google 帐户登录的用户的 key (称为 ActiveUser )
  • 如果用户未登录 Google 帐户(或正在使用隐身 session ),则 getTemporaryActiveUserKey()仍然返回一个键值,但这并不是该用户独有的。这就是我收到重复 key 的原因。
  • 为了确保在发布网络应用程序时仅返回唯一 key ,发布时应要求用户登录才能访问它。

根据上述内容,我的观点是 getTemporaryActiveUserKey()函数根本不应该为未登录的用户返回值,因为当它不是用户唯一的时,我看不到这样的键有任何用途。

关于google-apps-script - Google App 脚本 - 为什么 getTemporaryActiveUserKey() 为唯一用户返回相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52244279/

相关文章:

google-apps-script - 无法检索下一个对象 : iterator has reached the end error when iterating over shared Drive

google-apps-script - 刷新 token "error": "invalid_client" on google app script - new feature upgrade auth

javascript - 使用按钮启用禁用单选按钮&谷歌的 CSS 不会格式化 "action"按钮

javascript - 在新的谷歌网站中重定向表单

url - Google Apps Script 使用 replaceText() 使文本成为可点击的 URL

focus - 无法使用 HtmlService 简单地强制将焦点集中在独立 Google 应用程序中的文本输入上?

google-apps-script - 如何在函数调用之间放置 Utilities.sleep()?

javascript - 修改 Google 表单确认页面以使用 App Script .gs 显示时间戳

arrays - Apps 脚本从不同工作表获取数据的功能很慢,我该如何优化它?

jquery - 多次调用 google.script.run.withSuccessHandler