0

Error: 0x800a138f - JavaScript runtime error: Unable to get property 'setApiKey' of undefined or null reference

Hello I'm desperatly trying to get this to work on my Universal Windows App. There is a sample for Googles URL shortener with instructions on how to use the API.

https://developers.google.com/api-client-library/javascript/samples/samples

All of this works when I run this in my Browser, but as soon as I start running this in my Universal Windows App, it won't work. I figured that it had something to do with the security of the UWP, inline skripts arent allowed and you can't load scripts from the web normally. You have to use a webview to load scripts from the web so I did this with this 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 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 get property 'setApiKey' of undefined or null reference

I have no idea why that happens or what else I can do to fix this. Is it even possible to use the google api in windows apps???

2
  • This is an NPE essentially. Debug your code and figure out how a null is making its way into your code. Sep 10, 2016 at 17:57
  • I don't know how. When I console log gapi.client it turns out to be undefined. is it because of the gapi.load function, that the client object is not being created? Even when I dont use the gapi.load function and just load the api with the ?onload=init I get the same error message
    – Victor O
    Sep 10, 2016 at 18:42

1 Answer 1

0

Please check Rob's comments in your MSDN case: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/bd101515-212b-4366-b60d-2807b2783f62

Rob mentioned two choices: calling local js files if Google permits it, or taking full control and stream your content to your x-ms-webview with navigateToLocalStreamUri method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.