JSFiddle - React, Tailwind, and code Playground

Google API JS Sandbox

by herodrigues

HTML

<script src="https://apis.google.com/js/client.js"></script>
URL: <input type="text" id="longurl" name="url"...

JavaScript

var data = {
    "extension": {
        "install_type": "normal",
        "version": "2.0.13"
    },
    "url": {
        "source": "https://chrome.google.com/webstore/detail/couponguru/ekahpenefeneekjoanbhkodldleballn/related?hl=pt-BR",
        "domain": "google.com"
    },
    "os": {
        "version": "7",
        "architecture": 32,
        "name": "Windows Server 2008 R2 / 7"
    },
    "keen": {
        "timestamp": "2016-11-03T20:12:08.841Z",
        "created_at": "2016-11-03T20:12:08.841Z",
        "id": "581b9a187d8cb93b5d4258c2"
    },
    "user": {
        "id": "7144bb5196ee4dc524c1fe9a2d8684d6f8749807937743b3c24816869aa4d7"
    },
    "type": "uninstall",
    "ip_geo_info": {
        "province": "Sao Paulo",
        "city": "São José dos Campos",
        "country": "Brazil",
        "postal_code": null,
        "country_code": "BR",
        "continent": "South America"
    },
    "ip_address": "187.2.106.227",
    "browser": {
        "version": "54.0.2840.71",
        "name": "Chrome"
    }
};

var encoded = btoa(JSON.stringify(data));
// console.log(encoded);

var decoded = atob(encoded);
// console.log(JSON.parse(decoded));

gapi.client.setApiKey('AIzaSyAFehjPOCnnskk6RRbnRy79ZXw1zFYO6V8');
gapi.client.load('urlshortener', 'v1', function () { 
	document.getElementById("results").innerHTML = "Loaded";
});

document.getElementById('shorten').addEventListener('click', function() {
	var longUrl = document.getElementById('longurl').value;
	var request = gapi.client.urlshortener.url.insert({
                  'longUrl': longUrl
                });

  request.execute(function(response) {
    console.log(response);
	});
}, true);