Error: 0x800a138f - JavaScript runtime error: Unable to access 'setApiKey' property of undefined or null reference
Hello, I am struggling to make this work on my Universal Windows App. There is a sample for Google's URL shortener with instructions on how to utilize the API.
https://developers.google.com/api-client-library/javascript/samples/samples
Everything functions properly when I execute it in my web browser. However, when I try running it in my Universal Windows App, it fails to work. I suspect it has something to do with the security restrictions of the UWP. Inline scripts are not permitted and loading scripts from the web is restricted. A workaround is to use a webview to load scripts from the web, so I implemented the following webview:
<x-ms-webview id="UrlShortenerWebview"src="ms-appx-web:///Pages/URLShortener/URLShortener.html" style="width: 200px; height: 200px; border: 1px solid black;"></x-ms-webview>
This is the content of my URL Shortener HTML file:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="https://apis.google.com/js/api.js" type="text/javascript"></script>
<script>
function appendResults(text) {
var results = document.getElementById('results');
results.appendChild(document.createElement('P'));
results.appendChild(document.createTextNode(text));
}
function makeRequest() {
var request = gapi.client.urlshortener.url.get({
'shortUrl': 'http://goo,gl/fbsS'
});
request.then(function (response) {
appendResults(response.result.longUrl);
}, function (reason) {
console.log('Error: ' + reason.result.error.message);
});
}
function init() {
gapi.client.setApiKey('AIzaSyCzBnER6KmLiO2ZBIycZIPCEQEXxIrHnR0');
gapi.client.load('urlshortener', 'v1').then(makeRequest)
}
gapi.load("client", init);
</script>
</head>
<body>
<div id="results"></div>
</body>
</html>
Error: 0x800a138f - JavaScript runtime error: Unable to access 'setApiKey' property of undefined or null reference
I am unsure why this issue is occurring or what other approaches I can take to resolve it. Is it even feasible to use the Google API in Windows apps???