I have setup an Installable trigger that launches a google picker function when my google sheet is opened [showPicker()]. The google sheet can be accessed by a url by anyone.
When I open the google sheet the script runs fine and the file picker shows up on screen. However, when I logged into a different account that i shared the google sheet with, the script appears to not run and the file picker doesn't show when the spreadsheet is opened.
.GS file
function showPicker() {
var html = HtmlService.createHtmlOutputFromFile('Picker.html')
.setWidth(600)
.setHeight(425)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, 'Select CSV File');
}
function getOAuthToken() {
DriveApp.getRootFolder();
return ScriptApp.getOAuthToken();
}
Picker.html file
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
<script type="text/javascript">
var DIALOG_DIMENSIONS = {
width: 600,
height: 425
};
var pickerApiLoaded = false;
function onApiLoad() {
gapi.load('picker', {
'callback': function() {
pickerApiLoaded = true;
}
});
google.script.run.withSuccessHandler(createPicker)
.withFailureHandler(showError).getOAuthToken();
}
function createPicker(token) {
if (pickerApiLoaded && token) {
var docsView = new google.picker.DocsView()
.setIncludeFolders(true)
.setMimeTypes('application/vnd.google-apps.folder,text/csv')
//.setSelectFolderEnabled(true);
var picker = new google.picker.PickerBuilder()
.addView(docsView)
.enableFeature(google.picker.Feature.NAV_HIDDEN)
.hideTitleBar()
.setSize(DIALOG_DIMENSIONS.width - 2, DIALOG_DIMENSIONS.height - 2)
.setOAuthToken(token)
.setCallback(pickerCallback)
.setOrigin('https://docs.google.com')
.build();
picker.setVisible(true);
} else {
showError('Unable to load the file picker.');
}
}
/**
* A callback function that extracts the chosen document's metadata from the
* response object. For details on the response object, see
* https://developers.google.com/picker/docs/result
*
* @param {object} data The response object.
*/
function pickerCallback(data) {
var action = data[google.picker.Response.ACTION];
if (action == google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0];
var id = doc[google.picker.Document.ID];
// Show the ID of the Google Drive folder
//document.getElementById('result').innerHTML = id;
//Run Import CSV
google.script.run.withFailureHandler(onFailure)
.importCSVFromGoogleDrive(id);
//google.script.run.importCSVFromGoogleDrive(id);
google.script.host.close();
} else if (action == google.picker.Action.CANCEL) {
google.script.host.close();
}
}
function showError(message) {
document.getElementById('result').innerHTML = 'Error: ' + message;
}
function onFailure(error) {
var div = document.getElementById('output');
div.innerHTML = "ERROR: " + error.message;
}
</script>
</head>
<body>
<div>
<p id='result'></p>
<div id="output"></div>
</div>
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>
</body>
</html>
I have tried looking through the documentation on authorization for shared users, but I'm a bit lost and have no idea why the script will not launch?? Any help would be greatly appreciated :)
STACKDRIVER LOGS (Using other google acct):
Error - Sep 2, 2019, 6:05:36 PM - You do not have permission to call showModalDialog at showPicker(Code:724)
EXECECUTION TRANSCRIPT (Using other google acct):
[19-09-02 01:05:36:307 PDT] HtmlService.createHtmlOutputFromFile([Picker.html])[0 seconds]
[19-09-02 01:05:36:308 PDT] HtmlOutput.setWidth([600]) [0 seconds]
[19-09-02 01:05:36:308 PDT] HtmlOutput.setHeight([425]) [0 seconds]
[19-09-02 01:05:36:309 PDT] HtmlOutput.setSandboxMode([IFRAME]) [0 seconds]
[19-09-02 01:05:36:310 PDT] SpreadsheetApp.getUi() [0 seconds]
[19-09-02 01:05:36:315 PDT] Execution failed: You do not have permission to call showModalDialog (line 724, file "Code")
[0.004 seconds total runtime]