Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

mgufrone/react-native-google-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Google URL Shortener

This package is supposed to communicate between API of Google URL Shortener to your app.

Installation

You can run this package to use the package

npm install --save react-native-google-shortener

How to use the package

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');

Shorten URL

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);
})

Expand Shortened URL

// 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);
})

Contribution

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.