-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Check whether you are authenticated | ||
#' | ||
#' @description \ifelse{html}{\figure{api-both.svg}{options: | ||
#' alt='[Both]'}}{\strong{[Both]}} | ||
#' | ||
#' Check if the necessary token or cookies are stored on your computer | ||
#' already. By default, the function checks for the authentication of the | ||
#' research and hidden API. To learn how you can authenticate, look at the | ||
#' vignette for the research (\code{vignette("research-api", package = | ||
#' "traktok")}) or hidden (\code{vignette("unofficial-api", package = | ||
#' "traktok")}) API. | ||
#' | ||
#' @param research,hidden turn check on/off for the research or hidden API. | ||
#' @param silent only return if check(s) were successful, no status on the | ||
#' screen | ||
#' | ||
#' @return logical vector (invisible) | ||
#' @export | ||
#' | ||
#' @examples | ||
#' auth_check() | ||
auth_check <- function(research = TRUE, hidden = TRUE, silent = FALSE) { | ||
auth <- vector() | ||
if (research) { | ||
if (!isFALSE(get_token(auth = FALSE))) { | ||
auth <- c(research = TRUE) | ||
if (!silent) cli::cli_alert_success("Research API authenticated") | ||
} | ||
} | ||
if (hidden) { | ||
cookies <- try(cookiemonster::get_cookies("^(www.)*tiktok.com")) | ||
if (is.data.frame(cookies) && "tt_chain_token" %in% cookies$name) { | ||
auth <- c(auth, hidden = TRUE) | ||
if (!silent) cli::cli_alert_success("Hidden API authenticated") | ||
} | ||
} | ||
invisible(auth) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.