First, you will need to create a new Firebase project, and then enable the Firebase URL Shortener API. Once you have done that, you can get started with the following steps:
- Include the Firebase Javascript SDK in your page:
<script src="https://www.gstatic.com/firebasejs/7.8.1/firebase-app.js"></script>
- Initialize Firebase in your page:
firebase.initializeApp({
apiKey: "YOUR-API-KEY",
projectId: "YOUR-PROJECT-ID"
});
- Create a new instance of the Firebase URL Shortener:
var urlShortener = new firebase.urlShortener.UrlShortenerClient(firebase.initializeApp());
- Shorten a URL:
urlShortener.shorten("https://www.example.com")
.then(function(response) {
console.log(response.shortLink);
})
.catch(function(error) {
console.error(error);
});
You can find more information in the Firebase documentation:
https://firebase.google.com/docs/dynamic-links/url-shortener