I have a Google Sheet Code which has a UI part ie html and code.gs the problem is inside Google sheet I am getting a webpage and the authentication and other functions are working well but if I add the doGet() in code.gs and convert that to webapp the functions are not working and the scriptlets are displaying in the html page also the functions broke .
Since the code inside the html page is running in server side of the google app script sheet but it fails to run in client side as the reference are not directing to the server side code.gs
I need to make it work with the client side code , it should functional just like it work inside the Google spreadsheet
I am using Google Apps Scripts Oauth and getting a facebook token this is the Original work which successfully generate a token and access to facebook data Original Work
These are the codes
<div class="tab-content">
<!-- Home -->
<div id="ads" class="tab-pane fade in active">
<div id="page-content-wrapper">
<div class="hamburger is-closed" data-toggle="offcanvas">
<span class="hamb-top"></span>
<span class="hamb-middle"></span>
<span class="hamb-bottom"></span>
</div>
<div class="container">
<? if(!getService().hasAccess()) { ?>
<div class="row">
<div class="col-md-12 col-lg-12">
<p style="font-size:25px;">Features:</p>
</div>
</div>
<br />
<div class="row">
<div class="col-md-12" align='center'>
<a class="loginBtn loginBtn--facebook btn btn-info" href='<?=getService().getAuthorizationUrl()?>' target='_blank'>Authorize Facebook</a>
</div>
</div>
<? } else { ?>
<p style='color:green'>Authorization Success</p>
<div class="form-group">
<label for="accountData">Select Account:</label><span class="glyphicon glyphicon-question-sign help" title="Select Account To Export"></span>
<select id="accountData" style="width: 100%">
<? if (getService().hasAccess()) { ?>
<? var data = adAccounts() ?>
<? if (data != false) { ?>
<? data = data['facebookAccountData'] ?>
<optgroup label="Ad Accounts">
<? for (i=0; i<data.length; i++) { ?>
<option value="<?= data[i]['account_id'] ?>" data-type="facebookAds"><?= data[i]['name'] ?> (<?= data[i]['account_id'] ?>)</option>
<? } ?>
</optgroup>
<? } ?>
<? } ?>
</select>
</div>
the Login Button itself calling a function inside the code.gs but it is only work inside the google sheet but not in a web app or any html browser or client side So how to refer this into the code.gs
href='<?=getService().getAuthorizationUrl()
This is the code.gs PART
function fbAuth(){
var UI=HtmlService.createTemplate("<b><a href='<?=getService().getAuthorizationUrl()?>' target='_blank'>Click To Authorize</a></b><br /><? if(getService().hasAccess())"+
"{ ?> <?!= <p><span style='color:green'>Authorized Successfully</span></p> } else {?> <?!= <p><span style='color:red'>Not Authorized</span></p> }").evaluate()
SpreadsheetApp.getUi().showModalDialog(UI, "Facebook Authorization")
}
function getService() {
return OAuth2.createService('Facebook')
// Set the endpoint URLs.
.setAuthorizationBaseUrl('https://www.facebook.com/dialog/oauth')
.setTokenUrl('https://graph.facebook.com/v3.2/oauth/access_token')
// Set the client ID and secret.
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
// Set the name of the callback function that should be invoked to complete
// the OAuth flow.
.setCallbackFunction('authCallback')
//Set Scope
.setScope('ads_read manage_pages publish_pages pages_show_list')
// Set the property store where authorized tokens should be persisted.
.setPropertyStore(PropertiesService.getUserProperties());
}
function authCallback(request) {
var isAuthorized = getService().handleCallback(request);
if (isAuthorized) {
successUI(true)
showBar()
return HtmlService.createHtmlOutput('Success! You can close this tab.<script>window.top.close()</script>');
} else {
successUI(false)
showBar()
return HtmlService.createHtmlOutput('Denied. You can close this tab.<script>window.top.close()</script>');
}
}
function reset() {
var service = getService();
service.reset();
showBar()
SpreadsheetApp.getUi().alert("Token Reset Success!!")
}
function successUI(isAuth){
if(isAuth){
var UI=HtmlService.createTemplate("<b><span style='color:green'>Authorization Successful</span></b>").evaluate()
SpreadsheetApp.getUi().showModalDialog(UI, "Authorization Status") } else
{var UI=HtmlService.createTemplate("<b><span style='color:red'>Authorization Fail</span></b>").evaluate()
SpreadsheetApp.getUi().showModalDialog(UI, "Authorization Status")}
}