Guai.L
0
Q:

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)
}
0
if (interactive()) {
bitly_update_user(name = "John Malc", showRequestURL = TRUE)
}
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()
}
0
## In order to use bitly functions, you first need to authenticate. 
##                         For that execute 'bitly_auth()' in R console.
0
library("knitr")
library(urlshorteneR)
0
if (interactive()) {

bitly_retrieve_group(ui$default_group_guid)
bitly_retrieve_groups()
}
0
if (interactive()) {
bitly_app_details()
}
0

New to Communities?

Join the community