Advertisement
sriyanto

generateshortenurl

Jul 27th, 2021
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tinyurl_getShortLink(url) {
  2.     try {
  3.         if (url == undefined) {
  4.             throw 'url is empty or is not a valid url!'
  5.         }
  6.         let content = UrlFetchApp.fetch('https://tinyurl.com/api-create.php?url=' + encodeURI(url));
  7.         if (content.getResponseCode() != 200) {
  8.             return 'An error occured: [ ' + content.getContentText() + ' ]';
  9.         }
  10.         return content.getContentText();
  11.     } catch (e) {
  12.         return 'An error occured: [ ' + e + ' ]';
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement