This package is supposed to communicate between API of Google URL Shortener to your app.
You can run this package to use the package
npm install --save react-native-google-shortener
The first thing you need to do is set the Google API key. You can obtain to your Google Developer Console.
const { setKey, shorten, expand } = require('react-native-google-shortener');
setKey('your google api key');
Then, to shorten your long URL, you can use this code.
shorten('https://mgufron.com').then(response => {
console.log('shorten url', response.id);
console.log('long url', response.longUrl);
})
// first argument should shortened url
expand('https://goo.gl/').then(response => {
console.log(response.id);
console.log(response.longUrl);
});
Full example code would be something like this
const { setKey, shorten } = require('react-native-google-shortener');
setKey('your google api key');
shorten('https://mgufron.com').then(response => {
// do your thing
console.log('shorten url', response.id);
console.log('long url', response.longUrl);
});
expand('https://goo.gl/alskd').then(response => {
console.log(response.id);
console.log(response.longUrl);
console.log(response.status);
});
// include projection or analytics
expand('https://goo.gl/alkaslk').then(response => {
console.log(response.id);
console.log(response.longUrl);
console.log(response.status);
console.log(response.analytics);
})
I love feedback so you can put your feedback to Issues or make a pull request to this package. I love to get any comments regarding my work. Or you can click donate button below. Happy Coding.