New to Rstudio and I am trying to connect to the Rstudio connect to get statisitcs of all apps in the last 60 days. However. I do not receive the statistics and receive the below errors
rsc_server <- "https://rstudio.hartxxx.com/"
Sys.setenv("RSTUDIO_CONNECT_API_KEY" = rstudioapi::askForPassword("Enter Connect Token:Uxxx"))
library(httr)
rsc_get <- function(endpoint_call){
rsc_call <- paste0(rsc_server, "__api__/v1/", endpoint_call)
rsc_auth <- add_headers(Authorization = paste("Key", Sys.getenv("RSTUDIO_CONNECT_API_KEY")))
resp <- GET(rsc_call, rsc_auth)
content(resp)
}
rsc_users <- rsc_get("users")
names(rsc_users)
rsc_users$total
names(rsc_users$results[[1]])
five_days <- paste0(Sys.Date() - 60, "T00:00:00-00:00")
rsc_shiny <- rsc_get(paste0("instrumentation/shiny/usage?from=", five_days))
names(rsc_shiny$results[[1]])
library(purrr)
library(tibble)
shiny_usage <- map_dfr(
rsc_shiny$results,
~ tibble(
guid = .x$content_guid,
user = ifelse(is.null(.x$user_guid), "anonymous", .x$user_guid),
started = .x$started,
ended = .x$ended,
ver = .x$data_version
)
)
glimpse(shiny_usage)
Observations: 12
Variables: 6
$ content_guid <chr> "a261edd3-fa51-4878-8afc-b7fe662a6c37", "a261edd3-fa51-4878...
$ user_guid <chr> NA, NA, NA, NA, "e96068bd-5e9f-4a5a-ab87-483f084f13fa", NA,...
$ started <dttm> 2021-08-18 14:36:33, 2021-08-18 15:04:21, 2021-08-18 15:44...
$ ended <dttm> 2021-08-18 15:00:46, 2021-08-18 16:37:51, 2021-08-18 17:11...
$ data_version <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
$ session_duration <drtn> 24.21667 mins, 93.50000 mins, 87.56667 mins, 72.46667 mins..