datawookie / urlshorteneR

R package for shortening URLs.
5 stars 4 forks source link

urlshorteneR

A small library for generating short URLs in R.

The longurl package will expand URLs from a range of URL shortening services. There is a surprisingly large number of these services (check out the list). I tried this package and it does a great job of expanding shortened URLs. It does not provide a shortening service though or access to analytics.

Installation

You can install the library directly from the github repository.

library(devtools)
install_github("DataWookie/urlshorteneR")

Usage

Load the library.

library(urlshorteneR)

Authenticate for goo.gl.

key = "863558629146-3bh2qh1j4c976mf5dtm6n73gi85esn2h.apps.googleusercontent.com"
secret = "BmLO7fMzZWwexWDp4x0sNh_c"
shortener_authenticate(key, secret)

Shorten, expand and query analytics.

shorten.google("http://www.google.com")
expand.google("http://goo.gl/3WwfIY")
analytics.google("http://goo.gl/3WwfIY")

Authenticate for bitly.

key = "692987373a97579f9faca10e7c2ea15d6c56fd97"
secret = "752c5fe36d8596fcc73421090260ebe0d7cbc1a9"
shortener_authenticate(key, secret, "bitly")

Shorten, expand and query analytics.

shorten.bitly("http://www.google.com")
expand.bitly("http://bit.ly/1Qho4Y5")
analytics.bitly("http://bit.ly/1Qho4Y5")

goo.gl

Read the high level overview of Google's URL shortener API, more details can be found in the API documentation.

The first thing that you need to do is set up a project in the Google Developers' Console. The process can be broken down as follows:

  1. Visit the Google Developers' Console and select "Create Project".
  2. Choose an appropriate project name and select "Create".
  3. In the Project Dashboard select "Enable Google APIs for use in your apps".
  4. Click "URL Shortener API" and then select "Enable API".
  5. Click "Credentials" under "APIs & auth".
  6. Click "Add credentials" and then select "OAuth 2.0 client ID".
  7. Select "Configure consent screen" and fill in the required details.
  8. Select "Web application" and press "Create".
  9. Fill in the Authorised redirect URIs as directed below.

Further information on OAuth 2.0 authentication at Google can be found here and here.

bitly

Create an account on bitly. Login and then register a bitly application. Retrieve the Client ID and Client Secret for the application. Check out the information on bitly authentication. The details of bitly API are worth a read, but not essential because this functionality is implemented by urlshorteneR.

Notes on Setting up Applications

Redirect URI

Set this to http://localhost:1410.