Last active
April 18, 2018 05:11
-
-
Save daichan4649/165a71c8b8b033c452de55ccbf232065 to your computer and use it in GitHub Desktop.
[GAS] create short url (google, bitly)
This file contains hidden or 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
// Google URL Shortener | |
// https://developers.google.com/url-shortener/v1/getting_started | |
function createGoogleShortUrl(url) { | |
var result = UrlShortener.Url.insert({ | |
longUrl: url | |
}); | |
return result.id; | |
} |
This file contains hidden or 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
// Bitly | |
// https://dev.bitly.com/links.html#v3_shorten | |
const OAUTH_TOKEN = '[OAUTH_TOKEN]'; | |
function createBitlyUrl(url) { | |
var endpoint = 'https://api-ssl.bitly.com/v3/shorten?access_token=' + OAUTH_TOKEN + '&longUrl=' + url; | |
var result = UrlFetchApp.fetch(endpoint, {// | |
method: "GET", | |
contentType: "application/json;" | |
}); | |
var json = JSON.parse(result.getContentText('utf-8')); | |
return json.data.url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment