由WebApp访问的Library中的ScriptDb [英] ScriptDb in Library accessed by WebApp

查看:88
本文介绍了由WebApp访问的Library中的ScriptDb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Google Apps脚本项目,该项目作为一个可见的WebApp发布,作为访问用户运行。


$ b 这个WebApp包含一个Library项目,它具有访问 ScriptDb 的方法如下:

  function getDb(){
返回ScriptDb.getMyDb();
}

function save(props){
return getDb()。save(props);
}

我打算让每个访问用户运行一个WebApp(使用基于时间的触发器以访问Gmail),但是我希望使用 ScriptDb 独立于运行WebApp的用户存储数据。
所以我认为集中一个地方获取数据库实例一章来自Google Apps脚本文档适用于此处,但是在访问Web应用程序时出现以下错误:

您无权访问库MyDBLibrary ,由你的脚本使用,或已被删除。



我做错了什么?当从WebApp访问ScriptDb时,ScriptDb不打算独立于用户运行吗?

正确的,我转载了你所报道的一切。您最后遗漏的是将Library项目本身分享给公众。



执行此操作的方法是
1.打开Library项目在脚本编辑器
2.转到文件 - >共享
3.在谁有权限部分,将其设置为任何链接都可以查看(不需要编辑)的人。





如果没有这些,Apps Script现在就会知道向公众提供图书馆代码的好处。希望这可以帮助。

I created a Google Apps Script project that is published as a WebApp visible for anyone, running as the accessing user.

This WebApp includes a Library project, which has methods to access ScriptDb as following:

function getDb() {
  return ScriptDb.getMyDb();
}

function save(props) {
  return getDb().save(props);
}

I intend to have one WebApp running per accessing user (using time-based triggers to access Gmail), however I would like to use the ScriptDb to store data independently from the user running the WebApp. So I thought the chapter Centralizing a Place to Get a Database Instance from the Google Apps Script Documentation applies here, however I am getting the following error when accessing the WebApp:

You do not have access to library MyDBLibrary, used by your script, or it has been deleted.

Am I doing anything wrong? Was ScriptDb not intended to run independently of the user, when being accessed from a WebApp?

解决方案

Joscha - you have the set up right and I reproduced everything you've reported. The last thing you were missing was to the share the Library project itself to the public.

The way to do that is to 1. Open the Library project in the script editor 2. Go to File -> Share 3. In the "Who has access" section, set it to anyone with the link can View (dont need edit).

Without this, Apps Script will now know its ok to serve the library code to the public. Hope this helps.

这篇关于由WebApp访问的Library中的ScriptDb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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