const yourDynamicLinkDomain = "###"; // Please set your dynamic link domain.
function getShortUrl_(longUrl) {
const url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=" + apiKey;
const options = {
payload: JSON.stringify({
dynamicLinkInfo: {
dynamicLinkDomain: yourDynamicLinkDomain,
link: longUrl,
},
}),
contentType: "application/json",
};
const res = UrlFetchApp.fetch(url, options);
const { shortLink } = JSON.parse(res.getContentText());
return shortLink;
}
// Please run this function.
function main() {
// do something for retrieving the long URL in your actual script.
const longUrl = "###"; // It supposes that your long URL is put to longUrl.
const shortUrl = getShortUrl_(longUrl); // Here, the long URL is shortned. You can use this.
// If "options" is required to be used, please use this.
const options = {
};
const res = UrlFetchApp.fetch(shortUrl, options);
}
For More details about Create Dynamic Links with the REST API

Leave a Reply