When you call google.script.run in the client-side environment, you're requesting execution of a server side Apps Script function.
Your implementation of loadClient() doesn't make sense in the context of server-side Apps Script execution.
Here's a full, simple example of successfully triggering a Logger.log() call on the server-side by way of a client side button click:
client.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<script>
function registerListener() {
document.getElementById('callServerFunction').addEventListener('click', function() {
google.script.run
.withSuccessHandler(function() {
alert("Successfully called server function.");
})
.withFailureHandler(function() {
alert("Failed to call server function.");
})
.serverFunction();
});
}
</script>
<body onload="registerListener()">
<button id="callServerFunction">Call Server Side Function</button>
</body>
</html>
Code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile('client');
}
function serverFunction() {
Logger.log("Server function called.");
}
Server side logging results after the button is clicked
[18-06-10 13:48:20:359 PDT] Server function called.
Regarding the Javascript Google API Client Libraries (i.e. https://apis.google.com/js/api.js), that's not meant to be used in the Apps Script server side context. The whole point of Apps Script is that there is a laundry list of services ready to use immediately without any setup. In addition to not being compatible, trying to load the client-side JS libraries in the server side Apps Script context is simply redundant.
Similarly, trying to use the client-side JS libraries in client-side Apps Script code doesn't make too much sense either, as you have the full set of server-side functionality available via google.script.run.
loadClient()works when you clickload_button?eval()What is that for? Alsogapiis a PHP class, isn't it? I don't think that's an Apps Script class.https://apis.google.com/js/api.jsis client side code that you wan to run in the browser, then you can use thesrcattribute of a script tag. src attribute<head><script src="https://apis.google.com/js/api.js"></script></head>gapiis the Google API Client Library for Javascript.