Skip to content

Instantly share code, notes, and snippets.

@daichan4649
Last active April 18, 2018 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daichan4649/165a71c8b8b033c452de55ccbf232065 to your computer and use it in GitHub Desktop.
Save daichan4649/165a71c8b8b033c452de55ccbf232065 to your computer and use it in GitHub Desktop.
[GAS] create short url (google, bitly)
// 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;
}
// 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