スプレッドシートで短縮URLを作成したい

Googleスプレッドシートで、短縮URLを作成したいと思ったことはありませんか?スプレッドシートでURLのリンクを貼り付けた時に、URLが長いために短縮したいと思うこともあるかと思います。この場合は、Google Apps Scriptを使用して短縮URLを作成することができますよ。この記事では、スプレッドシートで短縮URLを作成する方法をご紹介していきます。
スプレッドシートで短縮URLを作成する方法
それでは、スプレッドシートで短縮URLを作成する方法を説明していきます。スプレッドシートで短縮URLを作成するには、外部のURL短縮サービス「Bitly」をGoogle Apps Scriptで使用できるように設定します。まずは下記リンク先にBitlyにアクセスして、新規登録を行いましょう。

また「Sign up with Google」をクリックした場合は、Googleアカウントを使用してサインアップを行うこともできますよ。ただし後述のトークン発行のために「Profile」からパスワードを設定する必要がある点には注意しましょう。「Change password」画面で「Current password」にGoogleアカウントのパスワード・「New password」・「Confirm new password」に新しいパスワードを設定すればOKです。





/** bitlyで短縮URLを作成する * * @tageturl {string} 変換するURL * @return 短縮URL * @customfunction */ function MakeShortLink(tageturl) { const URL = "https://api-ssl.bitly.com/v4/shorten"; const TOKEN = "APIのトークン"; // let payload = { "long_url" : tageturl, }; let params = { "method" : "post", "contentType" : "application/json", "headers": {Authorization: "Bearer " + TOKEN}, "payload" : JSON.stringify(payload) }; let ret = JSON.parse(UrlFetchApp.fetch(URL, params)); return ret["link"]; }

