4

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
  • 4,643
  • 1
  • 27
  • 34

2 Answers2

4

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).

Sharing settings

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

Arun Nagarajan
  • 5,547
  • 1
  • 22
  • 19
  • That did the trick - I thought it should be enough to give access to the person that is the owner of the using script. Sharing with anyone whoe has the link...hmm...so as long as I don't publish the project key I guess that is not a security risk, right? – Joscha Oct 29 '12 at 16:50
  • The ScriptDb instance is private to a project. Just ensure that any ScriptDb accessing method is appropriately scoped (you can make methods private in a library by adding '_' at the end). This way even if the code is accessible to someone else if they get hold of the project key, the data is never accessible - even if they import in the project, they can't access the ScriptDb instance. – Arun Nagarajan Oct 29 '12 at 17:05
-1

You may need to turn on development mode flag to make it work.

Here's what I did.

  1. User A: Created a Master spreadsheet and created an app script and saved it with version 1.0.
  2. User A: Gave access to this sheet to user B so they can use the common app script.
  3. User A: Gave project access key to user B. 4.User B: Created a spreadsheet and added resource library with project key.
  4. User B: Selected version 1.0.
  5. User B: Turned on development mode.

Note: if I follow steps 1 through 5, then I still see the same error saying I don't have permission or the script has been deleted. However, also doing step 6 will resolve the error and allow you to use the shared script.

Mig82
  • 4,856
  • 4
  • 40
  • 63