Created
June 25, 2017 16:02
-
-
Save jeromeetienne/f0bd6fe553488298454a7495650b7b22 to your computer and use it in GitHub Desktop.
goo.gl - url shortener - standalone example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<script type="text/javascript"> | |
// https://developers.google.com/url-shortener/v1/getting_started | |
// | |
function load() { | |
// get your keys from here https://developers.google.com/url-shortener/v1/getting_started#APIKey | |
gapi.client.setApiKey('XXX-YOUR-KEY-GOES-HERE-XXXX'); | |
gapi.client.load('urlshortener', 'v1', function() { | |
document.getElementById("result").innerHTML = ""; | |
var Url = | |
'https://jeromeetienne.github.io/AR.js/three.js/examples/augmented-webpages/examples/screenAsPortal/index.html#{"trackingBackend":"artoolkit","markerPageResolution":"1920x979"}'; | |
var request = gapi.client.urlshortener.url.insert({ | |
'resource': { | |
'longUrl': Url | |
} | |
}); | |
request.execute(function(response) { | |
if (response.id != null) { | |
str = "<b>Long URL:</b>" + Url + "<br>"; | |
str += "<b>Test Short URL:</b> <a href='" + response.id + "'>" + response.id + "</a><br>"; | |
document.getElementById("result").innerHTML = str; | |
} | |
else { | |
alert("Error: creating short url \n" + response.error); | |
} | |
}); | |
}); | |
} | |
window.onload = load; | |
</script> | |
<body> | |
<div id="result"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment