I have created a very simple Google Apps Script taken from the documentation here:
https://developers.google.com/apps-script/advanced/bigquery
I modified that script to use my own project id and to query a table in BigQuery in that project. When running the script from the script editor it works fine - however when I try to call it from my Sheet it first says "Loading" and then after a while says "Error: Login Required". I was never asked to authenticate nor give permission for anything. I tried packaging the script as a Sheets add-on for my organization and when I add the add-on it does ask for permission, but again I try to run the query I get the login required error. From the BigQuery console I can see that indeed no query was executed and from the Stackdriver Logging console I can see the login required errors.
{
insertId: "1qpzv6cfv6fswq"
jsonPayload: {
context: {
reportLocation: {
filePath: "Code"
functionName: "runQuery"
lineNumber: 86
}
}
message: "Login Required
at runQuery(Code:86)"
serviceContext: {
service: "blah"
}
}
labels: {
script.googleapis.com/process_id: "blah"
script.googleapis.com/project_key: "blah"
script.googleapis.com/user_key: "blah"
}
logName: "projects/sk-data-platform/logs/script.googleapis.com%2Fconsole_logs"
receiveTimestamp: "2018-03-31T20:20:53.173034608Z"
resource: {
labels: {
function_name: "runQuery"
invocation_type: "custom function"
project_id: "sk-data-platform"
}
type: "app_script_function"
}
severity: "ERROR"
timestamp: "2018-03-31T20:20:52.169Z"
}
All of the documentation I have seen indicates that Google Sheets should handle the authentication flow for me and the script should run in the context of the logged in user.
In this case my user is the owner of the Google Project so I have access to everything. Very confused at this point.