Reputation: 634
I have a few questions relating to publishing an add-on for Google Sheets.
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)?
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
Reputation: 2808
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.
Upvotes: 1
Reputation: 759
Yes, you can use the onOpen(e)
simple trigger as outlined in the documentation.
(https://developers.google.com/apps-script/guides/triggers/
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
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