Coder Social home page Coder Social logo

node-googl's Introduction

DISCONTINUED. Google discontinued their goo.gl URL shortener on March 30, 2019

Build Status NPM version

Installation

npm install -g goo.gl

Command-line Usage

$ goo.gl www.google.com
http://www.google.com -> http://goo.gl/fbsS

$ goo.gl http://goo.gl/fbsS
http://goo.gl/fbsS -> http://www.google.com/

$ goo.gl www.google.com http://goo.gl/fbsS nba.com
http://goo.gl/fbsS -> http://www.google.com/
http://www.google.com -> http://goo.gl/fbsS
http://nba.com -> http://goo.gl/d1T8

$ goo.gl --key aBcDeFGhIjKLMnOPqRsT www.spotify.com
http://www.spotify.com/ -> http://goo.gl/cJFAL

It'll shorten and/or expand one or more URLs at a time.

Module Usage

Most methods return promises.

var googl = require('goo.gl');

// Set a developer key (_required by Google_; see http://goo.gl/4DvFk for more info.)
googl.setKey('aBcDeFGhIjKLMnOPqRsT');

// Get currently set developer key
googl.getKey();

// Shorten a long url and output the result
googl.shorten('http://www.google.com/')
    .then(function (shortUrl) {
        console.log(shortUrl);
    })
    .catch(function (err) {
        console.error(err.message);
    });

// Expand a goo.gl url and output the result
googl.expand('http://goo.gl/fbsS')
    .then(function (longUrl) {
        console.log(longUrl);
    })
    .catch(function (err) {
        console.error(err.message);
    });

// Expand a goo.gl url and pass userIp for capping purposes
googl.expand('http://goo.gl/fbsS', { userIp: '127.0.0.1' })
    .then(function (longUrl) {
        console.log(longUrl);
    })
    .catch(function (err) {
        console.error(err.message);
    });

// Shorten a goo.gl url and pass quotaUser for capping purposes
// See: https://developers.google.com/console/help/#cappingusage
googl.shorten('www.spotify.com', { quotaUser: 'UserID' })
    .then(function (shortUrl) {
        console.log(shortUrl);
    })
    .catch(function (err) {
        console.error(err.message);
    });

// Shorten a goo.gl url and pass a referer to be used with referer restrictions.
// See: https://support.google.com/googleapi/answer/6310037?hl=en
googl.shorten('www.spotify.com', { referer: 'my.domain.com' })
    .then(function (shortUrl) {
        console.log(shortUrl);
    })
    .catch(function (err) {
        console.error(err.message);
    });

// Look up a short URL's analytics
// See: https://developers.google.com/url-shortener/v1/getting_started#url_analytics
googl.analytics('http://goo.gl/fbsS', {projection: 'ANALYTICS_CLICKS'})
    .then(function(result) {        
        console.log(result);
    })
    .catch(function (err) {
        console.error(err.message);
    });

googl.analytics('http://goo.gl/fbsS', {projection: 'FULL'})
    .then(function(result) {        
        console.log(result);
    })
    .catch(function (err) {
        console.error(err.message);
    });

googl.analytics('http://goo.gl/fbsS', {projection: 'ANALYTICS_TOP_STRINGS'})
    .then(function(result) {        
        console.log(result);
    })
    .catch(function (err) {
        console.error(err.message);
    });

//default to projection=FULL
googl.analytics('http://goo.gl/fbsS')
    .then(function(result) {        
        console.log(result);
    })
    .catch(function (err) {
        console.error(err.message);
    });

node-googl's People

Contributors

diegorbaquero avatar kaimallea avatar kevindjones avatar lloydwatkin avatar pudrescu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.