forked from xiph/aomanalyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gapi.js
31 lines (29 loc) · 838 Bytes
/
gapi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var gapi;
function googleJSClientLoaded() {
gapi.client.setApiKey("AIzaSyDF8nSRXwQKWZct5Tr5wotbLF3O8SCvjZU");
gapi.client.load('urlshortener', 'v1', function () {
shortenUrl(googleJSClientLoaded.url, googleJSClientLoaded.done);
});
}
function shortenUrl(url, done) {
if (!window.gapi || !gapi.client) {
googleJSClientLoaded.url = url;
googleJSClientLoaded.done = done;
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "//apis.google.com/js/client.js?onload=googleJSClientLoaded";
document.body.appendChild(script);
return;
}
var request = gapi.client.urlshortener.url.insert({
resource: {
longUrl: url
}
});
request.then(function (resp) {
var id = resp.result.id;
done(id);
}, function () {
done(url);
});
}