Tutorial for urlshorteneR

dmpe @ github


This package wrapps Bit.ly & Goo.gl API. In order to begin shortening URLs and downloading usefull statistics, there is one requirement, which is to authenticate using OAUTH2 for each service (of course, if you need both of them)


See ??googl_auth. Please do not use my API Keys as they may not work properly.


An Example for User Metrics

Official API documentation http://dev.bitly.com/user_metrics.html.

Method below returns my most-clicked Bit.ly links (ordered by number of clicks) in a given time period.

## In order to use google or bitly functions, you first 
## need to authenticate. For that execute '?googl_auth' in R console.
# print(getwd())
# btoken_path <- file.path("..", "tests", "testthat", "bitly_token.rds")
# gtoken_path <- file.path("..", "tests", "testthat", "googl_token.rds")
if (interactive()) {

# bitly_token <- readRDS("../tests/testthat/bitly_token.rds")
# googl_token <- readRDS("../tests/testthat/googl_token.rds")

# You should register a new pair of keys yourself. DO NOT USE MINE as this may not work. 
# bitly_token <- bitly_auth(key = "be03aead58f23bc1aee6e1d7b7a1d99d62f0ede8", secret = "b7e4abaf8b26ec4daa92b1e64502736f5cd78899")

bitly_UserMetricsPopularLinks(unit = "month", units = -1, limit = 100)

An Example for User Info/History

Official API documentation http://dev.bitly.com/user_info.html.

The first method returns an information about myself, whereas the second one returns a list of tracking domains I have configured (I have none).

if (interactive()) {



An Example for Domains

Official API documentation http://dev.bitly.com/domains.html.

This will query whether a given domain is a valid Bit.ly PRO domain (nyti.ms is).

if (interactive()) {

bitly_IsProDomain(domain = "nyti.ms")

An Example with a dataframe and bulk shortening

if (interactive()) {
  df <- data.frame(pubDate = rep("2016-02-10", 4),
                   link = c(NA,"http://www.opencoesione.gov.it/progetti/1misepac01_000443/",
                            "http://www.opencoesione.gov.it/progetti/1misepac01_000031/", ""),
                   stringsAsFactors = FALSE)
  fin = NULL
  for (p in 1:length(df$link)) {
    fin[[p]] <- bitly_LinksShorten(longUrl = df$link[p])

BEWARE: This will proceed only with the two real links, not with the NA, NULL or an empty string. Therefore, you will recieve X number of messages describing the error. These, however, will not stop the flow of the code (i.e. are not errors).


if (interactive()) {

# googl_auth(key = "806673580943-78jdskus76fu7r0m21erihqtltcka29i.apps.googleusercontent.com", secret = "qItL-PZnm8GFxUOYM0zPVr_t")

g2 <- googl_LinksShorten(longUrl = "https://developers.google.com/url-shortener/v1/url/insert")
g1 <- googl_LinksExpand(shortUrl = "http://goo.gl/vM0w4", showRequestURL = F)


isgd_LinksShorten(longUrl = "http://debil.cz/", showRequestURL = TRUE)
## The requested URL has been this:  http://is.gd/create.php?format=json&url=http%3A%2F%2Fdebil.cz%2F&logstats=0
## [1] "https://is.gd/4oIAXJ"

What has (not) been implemented for Bit.ly:

Based on http://dev.bitly.com/

http://dev.bitly.com/user_info.html Implemented Yes/No
/v3/oauth/app NOT
/v3/user/info Yes
/v3/user/link_history Yes
/v3/user/network_history NOT
/v3/user/tracking_domain_list Yes
http://dev.bitly.com/link_metrics.html Implemented Yes/No
/v3/link/clicks Yes
/v3/link/countries Yes
/v3/link/encoders Yes
/v3/link/encoders_by_count Yes
/v3/link/encoders_count Yes
/v3/link/referrers Yes
/v3/link/referrers_by_domain Yes
/v3/link/referring_domains Yes
http://dev.bitly.com/user_metrics.html Implemented Yes/No Premium
/v3/user/clicks Yes
/v3/user/countries Yes
/v3/user/popular_earned_by_clicks NOT Yes
/v3/user/popular_earned_by_shortens NOT Yes
/v3/user/popular_links Yes
/v3/user/popular_owned_by_clicks NOT Yes
/v3/user/popular_owned_by_shortens NOT Yes
/v3/user/referrers Yes
/v3/user/referring_domains Yes
/v3/user/shorten_counts Yes
http://dev.bitly.com/domains.html Implemented Yes/No Premium
/v3/bitly_pro_domain Yes No
/v3/user/tracking_domain_clicks NOT Yes (cannot do unless sombody helps)
/v3/user/tracking_domain_shorten_counts NOT Yes (cannot do unless sombody helps)
http://dev.bitly.com/links.html Implemented Yes/No Premium
/v3/expand Yes
/v3/info Yes
/v3/link/lookup Yes
/v3/shorten Yes
/v3/user/link_edit NOT No
/v3/user/link_lookup NOT No
/v3/user/link_save NOT No
/v3/user/save_custom_domain_keyword NOT Yes

What has been implemented for Goo.gl:

I believe everything. If not, let you me know.