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.
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.
library(urlshorteneR)
# 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)
}
## link clicks
## 1 http://bit.ly/DPetrov 5
## 2 http://bit.ly/1IZgFLV 1
## 3 http://bit.ly/1hpfNzy 1
Official API documentation http://dev.bitly.com/link_metrics.html.
This returns users, who have encoded http://bit.ly/DPetrov
link sorted by the number of clicks on each encoding user’s link.
if (interactive()) {
bitly_LinksMetricsEncodersByCount(link = "http://bit.ly/DPetrov", my_network = "false", limit = 100)
}
## count link user ts
## 1 6 http://bit.ly/1hpfNzy o_5udd1hb1d8 2014-02-24 14:19:45
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()) {
bitly_UserInfo()
bitly_UserTrackingDomains()
}
## It seems that you don't have any tracking 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")
}
## A short domain: nyti.ms is a valid bitly pro domain
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")
g2
g1 <- googl_LinksExpand(shortUrl = "http://goo.gl/vM0w4", showRequestURL = F)
g1
}
## Auto-refreshing stale OAuth token.
## $original_data
## kind id
## 1 urlshortener#url http://goo.gl/vM0w4
## longUrl
## 1 http://www.bi-verdict.com/fileadmin/FreeAnalyses/consolidations.htm
## status created
## 1 OK 2013-05-20T15:12:07.325+00:00
##
## $analytics
## $analytics$allTime
## $analytics$allTime$shortUrlClicks
## [1] "8"
##
## $analytics$allTime$longUrlClicks
## [1] "8"
##
## $analytics$allTime$referrers
## count id
## 1 5 www.slideshare.net
## 2 2 unknown
## 3 1 de.slideshare.net
##
## $analytics$allTime$countries
## count id
## 1 2 DE
## 2 1 BD
## 3 1 HK
## 4 1 IN
## 5 1 NO
## 6 1 NZ
## 7 1 US
##
## $analytics$allTime$browsers
## count id
## 1 4 Chrome
## 2 2 MSIE
## 3 1 Firefox
## 4 1 Safari
##
## $analytics$allTime$platforms
## count id
## 1 7 Windows
## 2 1 Macintosh
##
##
## $analytics$month
## $analytics$month$shortUrlClicks
## [1] "0"
##
## $analytics$month$longUrlClicks
## [1] "0"
##
##
## $analytics$week
## $analytics$week$shortUrlClicks
## [1] "0"
##
## $analytics$week$longUrlClicks
## [1] "0"
##
##
## $analytics$day
## $analytics$day$shortUrlClicks
## [1] "0"
##
## $analytics$day$longUrlClicks
## [1] "0"
##
##
## $analytics$twoHours
## $analytics$twoHours$shortUrlClicks
## [1] "0"
##
## $analytics$twoHours$longUrlClicks
## [1] "0"
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] "http://is.gd/4oIAXJ"
Based on http://dev.bitly.com/
http://dev.bitly.com/user_info.html | Implemented Yes/No |
---|---|
/v3/oauth/app | (NOT, see below) |
/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 |
I believe everything. If not, let you me know.