I'm new to Web Scripts and deploying web apps, I have an issue where I require users to authorize permission to use the web app, but nothing pops up to request for said authorization.
I found this post here and it seems to be what I needed but I'm unsure how would I use it. I tried calling onOpen function at the start of my doGet but nothing happens. I also don't see where/when the authorize function is being called. My Web App is also using sheets, so I deleted any lines of code dealing with DocumentApp.
Here is my modified version of the code
function onOpen() {
if(!UserProperties.getProperty('author')){
var html = HtmlService.createHtmlOutputFromFile('index1')
.setTitle("Install Menu").setWidth(400);
}else{
var html = HtmlService.createHtmlOutputFromFile('index2')
.setTitle("Mailmerge Menu").setWidth(400);
}
}
function authorize(){
UserProperties.setProperty('author','yes');
var html = HtmlService.createHtmlOutput('Authorization complete<br>Thanks<br><br>please refresh your browser').setTitle("Confirmation").setWidth(400);
}
This is my doGet function just in case I was not utilizing the functions correctly.
function doGet(e)
{
onOpen();
var result;
var sheets = SpreadsheetApp.getActiveSheet();
var values = [];
// Get row 1 data
for( var i = 3; i <= 16; ++i)
{
var char = String.fromCharCode('A'.charCodeAt() + i) // Increment char
values.push(sheets.getRange(char + 1).getValue());
}
// Get row 2 data
for( var i = 3; i <= 16; ++i)
{
var char = String.fromCharCode('A'.charCodeAt() + i) // Increment char
values.push(sheets.getRange(char + 2).getValue());
}
var result = {result:values};
var JsonValue = JSON.stringify(result);
return ContentService.createTextOutput(JsonValue.toString()).setMimeType(ContentService.MimeType.JSON);
}
I know I can set the web app to execute as me by anyone, which does work, but I would like be able to allow other users to authorize themselves to execute the app.
Edit: I'm using Unity's WebRequest class to call the Get from my web app.
_webRequest = UnityWebRequest.Get("web app url here");
_webRequest.SendWebRequest();
And on receiving the response I will parse it and use the data in "result" in a separate class
if (_webRequest != null && _webRequest.isDone)
{
result = JsonUtility.FromJson<WebResponsePacket>
(_webRequest.downloadHandler.text);
Debug.Log("Successful Request");
return true;
}