3
votes

I've noticed that Google spreadsheet* custom menus (see code below) are not displayed for anonymous users i.e. users who access the spreadsheet directly from the URL (Link to share); you need to sign first.
*The spreadsheet is shared and the the permissions are "Anyone with the link can edit".

Is this the expected behaviour?
Is there any workaround to make custom menus available to users without having to sign-in first?

Code (from Google)**:

function myOnOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [ {name: "Say Hi", functionName: "sayHi"},
                      {name: "Say Hello", functionName: "sayHello"} ];
  ss.addMenu("Tutorial", menuEntries);
}

function sayHi() {
  Browser.msgBox("Hi");
}

function sayHello() {
  Browser.msgBox("Hello");
}

**The onOpen function has been renamed myOnOpen and is associated to an installable trigger. I've verified that it runs in the context of the spreadsheet owner.

TIA,

Olivier

2

2 Answers

2
votes

From an answer by +Samantha to a similar thread in the Google Docs Help Forum

In order for Scripts to run on a Google Sheet, the user must be logged in and have "can edit" rights. This means that anonymous users will not be able to run a Script.

If you would like to see this functionality added to Scripts, I recommend navigating to the Google Developers' Apps Script support page and pressing the "Send Feedback" button.

Note: I just posted the same quote in another answer to a similar question (Showing sidebar for viewers).

-1
votes

From the Apps Script Custom Function Docs.

Permissions and Custom Functions

Custom functions can read data from the current Spreadsheet and can call anonymous services such as SOAP, UrlFetch and Google Translate. An anonymous service is a service that does not require user credentials to run.

However, custom functions have some restrictions that other functions do not have. For example, custom functions run silently and are not permitted to access user-specific services. A user-specific service is a service that is tied to a particular user, such as Google Calendar. User-specific services may access private data, such as Google Calendar, or may act as the user, performing tasks such as sending email.

That being said, I am unsure how to determine which services are user credential limited.

Best of luck,

Jacob