vzh*_*vko 5 google-apps-script
在谷歌应用程序脚本项目中,我有一些情况需要存储一些敏感用户的数据以供以后执行。假设在第一次执行期间,用户提供了一些数据,而脚本第二次使用该数据。
有很多方法可以做到这一点,比如保存在一些谷歌文档中或将其保存在 g 驱动器中。但是,我认为最干净的方法是将它存储在PropertiesService.getUserProperties() 中
它工作得很好,但是我不确定这种方法是否足够安全。目前尚不清楚这些数据是如何存储的。我找不到任何技术说明。我浏览了 cookie,看起来它不使用 cookie。也许,它存储在 G 服务器上的某个地方,但是其他一些脚本是否能够读取我放入 UserProperties 中的数据?此外,不清楚设置属性的生命周期是多少,它们是否可以永远驻留在那里,直到某个脚本删除它?
更新
在Going GAS书中关于属性服务的一章中,我发现了一些有趣的注释
当 Apps Script 首次启动时,特定用户可以访问 UserProperties,而不是绑定到特定脚本。如今,每个脚本都有自己的 UserProperties 类,只能由特定用户从该脚本中访问该类。
这意味着,其被存储在UserProperties通过任何数据SCRIPT1下USER1不在访问SCRIPT2下USER1。我实际上进行了快速测试以确认这一点。
另一个注意事项
Apps Script Properties 服务位于云端,因此与任何特定机器、环境或操作系统无关。
这部分证实了我的假设,即属性存储在运行 *.gs 脚本的 G 服务器上。
考虑到这一点,我会说使用属性服务在某种程度上是可靠和安全的。
很高兴听到有关此的任何评论。
取决于你如何界定它的范围。
它的范围可以限定为一个脚本:
var scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperty('SERVER_URL', 'http://www.example.com/');
Run Code Online (Sandbox Code Playgroud)脚本的一名用户
var userProperties = PropertiesService.getUserProperties();
userProperties.setProperty('DISPLAY_UNITS', 'metric');
Run Code Online (Sandbox Code Playgroud)或一份文件
var documentProperties = PropertiesService.getDocumentProperties();
documentProperties.setProperty('SOURCE_DATA_ID', '1234567890abcdefghijklmnopqrstuvwxyz');
Run Code Online (Sandbox Code Playgroud)这是来自文档的访问表。
+--------------------+---------------------------------------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+
| | Script Properties | User Properties | Document Properties |
+--------------------+---------------------------------------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+
| Method to access | getScriptProperties() | getUserProperties() | getDocumentProperties() |
| Data shared among | All users of a script, add-on, or web app | The current user of a script, add-on, or web app | All users of an add-on in the open document |
| Typically used for | App-wide configuration data, like the username and password for the developer's external database | User-specific settings, like metric or imperial units | Document-specific data, like the source URL for an embedded chart |
+--------------------+---------------------------------------------------------------------------------------------------+-------------------------------------------------------+-------------------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
没有明确说明这些属性的生命周期或它们到底存储在哪里,但从配额文档中,我们知道:
| 归档时间: |
|
| 查看次数: |
2130 次 |
| 最近记录: |