Michael Yousef
Michael Yousef

Reputation: 634

Google Apps Script publishing questions

I have a few questions relating to publishing an add-on for Google Sheets.

  1. I have a script right now set up with an on load trigger to run the script. Is it possible to have my script run the same way if it's published as an add-on? If not, I guess I can probably have the user click some sort of menu option to run it (which calls a specific function in my script)?

  2. If I publish the script, can users see the code? The problem I have right now is that the script I'm using connects to an API that uses an API key to limit user requests. The key is meant to be private, and for now it's fine that I just have it in the code since I'm only using it privately. I don't have a way to hide the API key from the users if the code is public though, so it would really be a problem if it was public.

Upvotes: 0

Views: 69

Answers (3)

Andrew Roberts
Andrew Roberts

Reputation: 2808

  1. "I have a script right now set up with an on load trigger to run the script."

If this means that you are trying to do anything apart from create a custom menu in the onOpen() it could fail as it may not have the authorisation to run; you are limited to what you can do in onOpen() in an add-on. Take a look at the add-on authorisation cycle.

  1. The user can't see your add-on code. However if you were planning to open source your code at any point you can store private things like API keys using the Properties Service that can be manually set in the script editor (File>Project Properties>Script Properties) or by running a bit of code that you then delete.

Upvotes: 1

Eric Dauenhauer
Eric Dauenhauer

Reputation: 759

Answer to question 1:

Yes, you can use the onOpen(e) simple trigger as outlined in the documentation. (https://developers.google.com/apps-script/guides/triggers/

Answer to question 2:

As Amit Agarwal mentioned in their answer, the code for a published add-on will be private. Users will not be able to see your API key.

Upvotes: 0

Amit Agarwal
Amit Agarwal

Reputation: 11278

If you publish the Google Script as a web app or as an add-on, others cannot see the source code of the script.

Upvotes: 1

Related Questions