diff --git a/R/get_data.R b/R/get_data.R index 4e3e2db..b8dbc1f 100755 --- a/R/get_data.R +++ b/R/get_data.R @@ -102,10 +102,12 @@ get_n <- function(scope, n = 10000, start_date = lubridate::dmy("01-01-1900"), c #' @param url url to visit and get data from #' @param parse logical. whether to return parsed data or not. Defautls to \code{TRUE}. #' @export -get_data <- function(url, parse = T, vpn = F, cookie = "", time_out = 10, docker = F){ +get_data <- function(url, parse = T, vpn = F, cookie = "", time_out = 10){ + + if(!stringr::str_detect(url, "&_signature=")){ - final_url <- get_signature(url, docker = docker) + final_url <- get_signature(url) } else { final_url <- url } diff --git a/R/meta.R b/R/meta.R index b7d42df..3e7185a 100644 --- a/R/meta.R +++ b/R/meta.R @@ -42,6 +42,8 @@ tk_auth <- function(cookie, ua, id_cookie, docker = F) { } else { message("TIKTOK_DOCKER found. Tiktokr will use a docker container to sign the urls") } + } else { + if(Sys.getenv("TIKTOK_DOCKER") == "") message("TIKTOK_DOCKER found. Tiktokr will use a docker container to sign the urls") } ## Tiktok Cookie diff --git a/R/signature.R b/R/signature.R index 80c6235..ecfaecf 100644 --- a/R/signature.R +++ b/R/signature.R @@ -1,10 +1,11 @@ #' @export -get_signature <- function(urls, docker = F){ - - if(!docker) out <- get_puppeteer_signature(urls) - if(docker) out <- urls %>% purrr::map_chr(get_docker_signature) - # if(!is.null(port)) out <- urls %>% purrr::map_chr(get_api_signature, port = port) +get_signature <- function(urls){ + if(Sys.getenv("TIKTOK_DOCKER") == "TRUE"){ + out <- urls %>% purrr::map_chr(get_docker_signature) + } else { + out <- get_puppeteer_signature(urls) + } paste0(urls, "&_signature=", out) } diff --git a/lab.Rmd b/lab.Rmd index 9571159..7ccf7d6 100755 --- a/lab.Rmd +++ b/lab.Rmd @@ -21,6 +21,12 @@ b$signature ```{r} + + + + + + dockeR::doc_copy("tiktoksignature", from = "../tiktok_signature/api.R", to_cont = "/usr/api.R") dockeR::doc_copy("tiktoksignature", from = "../tiktok_signature/run_api.R", to_cont = "/usr/run_api.R") @@ -42,11 +48,16 @@ res$r_code 1. Install docker. Once it is installed you can verify with `docker -v``` -2. Build the image of a container able to generate tiktok signature (this needs to be done only once) +2. Set `docker = T` in tk_auth() and run the following test: ```{r} - +tk_init() +if(stringr::str_length(get_docker_signature("")) > 16){ + message("Signature successfull, your docker container is working.") +} else { + message("Unable to get the signature") +} ```