Skip to content

Instantly share code, notes, and snippets.

@onozaty
Last active December 11, 2015 00:49
Show Gist options
  • Save onozaty/4519326 to your computer and use it in GitHub Desktop.
Save onozaty/4519326 to your computer and use it in GitHub Desktop.
Google URL Shortener
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
console.log(request.responseText);
} else {
console.log('error!! status code:' + request.status);
}
}
};
request.open(
'POST',
'https://www.googleapis.com/urlshortener/v1/url?key={your API Key}',
true);
request.setRequestHeader('Content-Type', 'application/json');
request.send("{'longUrl': 'http://www.google.com/'}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment