diff --git a/R/api_research.r b/R/api_research.r index f39c1c1..a3c7f24 100644 --- a/R/api_research.r +++ b/R/api_research.r @@ -16,13 +16,15 @@ #' @param is_random Whether the query is random (defaults to FALSE) #' @param max_pages results are returned in batches/pages with 100 videos. How #' many should be requested before the function stops? +#' @param parse Should the results be parsed? Otherwise, the original JSON +#' object is returned as a nested list. #' @param cache should progress be saved in the current session? It can then be #' retrieved with \code{last_query()} if an error occurs. But the function #' will use extra memory. #' @param verbose should the function print status updates to the screen? #' @param token The authentication token (usually supplied automatically after #' running auth_research once) -#' @return A data.frame of parsed TikTok videos +#' @return A data.frame of parsed TikTok videos (or a nested list). #' @export #' @examples #' \dontrun{ @@ -72,6 +74,7 @@ tt_search_api <- function(query, search_id = NULL, is_random = FALSE, max_pages = 1, + parse = TRUE, cache = TRUE, verbose = TRUE, token = NULL) { @@ -156,14 +159,19 @@ tt_search_api <- function(query, if (verbose) cli::cli_progress_done() } - if (verbose) { - cli::cli_progress_done() - cli::cli_progress_step("Parsing data") + if (parse) { + if (verbose) { + cli::cli_progress_done() + cli::cli_progress_step("Parsing data") + } + videos <- parse_api_search(videos) + if (verbose) cli::cli_progress_done() + } else { + attr(videos, "search_id") <- the$search_id + attr(videos, "cursor") <- the$cursor } - out <- parse_api_search(videos) - if (verbose) cli::cli_progress_done() - return(out) + return(videos) } diff --git a/R/parse_research.r b/R/parse_research.r index b008eb1..2ac096e 100644 --- a/R/parse_research.r +++ b/R/parse_research.r @@ -6,6 +6,8 @@ parse_api_search <- function(x) { author_name = vpluck(x, "username", val = "character"), view_count = vpluck(x, "view_count", val = "integer"), comment_count = vpluck(x, "comment_count", val = "integer"), + share_count = vpluck(x, "share_count", val = "integer"), + like_count = vpluck(x, "like_count", val = "integer"), region_code = vpluck(x, "region_code", val = "character"), create_time = as.POSIXct(vpluck(x, "create_time", val = "integer"), tz = "UTC", origin = "1970-01-01"), diff --git a/man/tt_search_api.Rd b/man/tt_search_api.Rd index f0302dd..2b00aa8 100644 --- a/man/tt_search_api.Rd +++ b/man/tt_search_api.Rd @@ -14,6 +14,7 @@ tt_search_api( search_id = NULL, is_random = FALSE, max_pages = 1, + parse = TRUE, cache = TRUE, verbose = TRUE, token = NULL @@ -28,6 +29,7 @@ tt_query_videos( search_id = NULL, is_random = FALSE, max_pages = 1, + parse = TRUE, cache = TRUE, verbose = TRUE, token = NULL @@ -51,6 +53,9 @@ picking up an old search)} \item{max_pages}{results are returned in batches/pages with 100 videos. How many should be requested before the function stops?} +\item{parse}{Should the results be parsed? Otherwise, the original JSON +object is returned as a nested list.} + \item{cache}{should progress be saved in the current session? It can then be retrieved with \code{last_query()} if an error occurs. But the function will use extra memory.} @@ -61,7 +66,7 @@ will use extra memory.} running auth_research once)} } \value{ -A data.frame of parsed TikTok videos +A data.frame of parsed TikTok videos (or a nested list). } \description{ \ifelse{html}{\figure{api-research.svg}{options: alt='[Works on: