unshorten url in R
decode_short_url <- function(url, ...) {
# PACKAGES #
require(RCurl)
# LOCAL FUNCTIONS #
decode <- function(u) {
Sys.sleep(0.5)
x <- try( getURL(u, header = TRUE, nobody = TRUE, followlocation = FALSE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")) )
if(inherits(x, 'try-error') | length(grep(".*Location: (\\S+).*", x))<1) {
return(u)
} else {
return(gsub('.*Location: (\\S+).*', '\\1', x))
}
}
# MAIN #
gc()
# return decoded URLs
urls <- c(url, ...)
l <- vector(mode = "list", length = length(urls))
l <- lapply(urls, decode)
names(l) <- urls
return(l)
}
4.17
6
library("knitr")
library(urlshorteneR)
Thank you!
6
0
4
2
if (interactive()) {
bitly_update_user(name = "John Malc", showRequestURL = TRUE)
}
Thank you!
2
0
4.5
10
if (interactive()) {
bitly_retrieve_group(ui$default_group_guid)
bitly_retrieve_groups()
}
Thank you!
10
0
4.25
4
if (interactive()) {
bitly_app_details()
}
Thank you!
4
0
5
2
## In order to use bitly functions, you first need to authenticate.
## For that execute 'bitly_auth()' in R console.
Thank you!
2
0
0
0
if(interactive()) {
opts_knit$set(root.dir = "~/Documents/Documents2/R-package-urlshortener")
bitly_token <- readRDS("tests/bitly_local_token.rds")
# 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()
ui <- bitly_user_info(showRequestURL = TRUE)
is_bitly_user_premium_holder()
}
Thank you!
0
0
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-27 22:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-27 22:45:24 income of a web developer
-
Other 2022-03-27 22:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-27 22:30:45 rick roll embed code
-
Other 2022-03-27 22:20:08 Circuit_04_Potentiometer
-
Other 2022-03-27 22:20:05 iterative power
-
Other 2022-03-27 22:15:11 flutter run all
-
Other 2022-03-27 22:10:05 when is karlson release
-
Other 2022-03-27 22:10:02 wp .htaccess example
-
Other 2022-03-27 22:00:08 bash pause in file read line by line