urlshorteneR
wrapps 2 URL services Bit.ly and is.gd/v.gd. In order to begin shortening URLs and downloading usefull statistics about short links, you have to – in the case of http://bit.ly – authenticate using OAuth2.0.
For is.gd/v.gd there is no authentication needed.
Return some basic information about my user on Bit.ly. Additionally, is my account a “premium” one?
library("knitr")
library(urlshorteneR)
## In order to use bitly functions, you first need to authenticate.
## For that execute 'bitly_auth()' in R console.
if(interactive()) {
$set(root.dir = "~/Documents/Documents2/R-package-urlshortener")
opts_knit<- readRDS("tests/bitly_local_token.rds")
bitly_token
# You can register a new pair of keys yourself - but you can also use mine - an option which is also by default
# bitly_token <- bitly_auth(key = "be03aead58f23bc1aee6e1d7b7a1d99d62f0ede8", secret = "f9c6a3b18968e991e35f466e90c7d883cc176073")
# bitly_token <- bitly_auth()
<- bitly_user_info(showRequestURL = TRUE)
ui is_bitly_user_premium_holder()
}
We can also decide to update my username with a different one.
if (interactive()) {
bitly_update_user(name = "John Malc", showRequestURL = TRUE)
}
And what about the metadata about our OAUTH application?
if (interactive()) {
bitly_app_details()
}
This retrieves information about a single group that user belongs to and and then about all groups that user are associated with.
if (interactive()) {
bitly_retrieve_group(ui$default_group_guid)
bitly_retrieve_groups()
}
Official API documentation https://dev.bitly.com/api-reference.
The first method returns an information about myself.
if (interactive()) {
bitly_user_info()
}
if (interactive()) {
<- data.frame(pubDate = rep("2016-02-10", 4),
df link = c("http://wwaaw.opencasdoesione.gov.it/progetti/1misepac01_000443/",
"http://wwssw.opencasdoesione.gov.it/progetti/1misepac01_000031/"),
stringsAsFactors = FALSE)
df
= NULL
fin for (p in 1:length(df$link)) {
<- bitly_create_bitlink(long_url = df$link[p])
fin[[p]]
} }
BEWARE: This will proceed only with the two real links, not with the NA, NULL or an empty strings. These, however, will stop the flow of the code (i.e. are errors).
isgd_LinksShorten(longUrl = "http://cnn.com/", showRequestURL = TRUE)
## The requested URL has been this: http://is.gd/create.php?format=json&url=http%3A%2F%2Fcnn.com%2F&logstats=0
## [1] "https://is.gd/kK08He"
vgd_LinksShorten(longUrl = "http://cbs.com/", showRequestURL = TRUE)
## The requested URL has been this: https://v.gd/create.php?format=json&url=http%3A%2F%2Fcbs.com%2F&logstats=0
## [1] "https://v.gd/UnFdGV"