#' Authenticate this session
#'
#' A wrapper for \link[googleAuthR]{gar_auth} and \link[googleAuthR]{gar_auth_service}
#'
#' @param new_user If TRUE, reauthenticate via Google login screen
#' @param no_auto Will ignore auto-authentication settings if TRUE
#'
#' If you have set the environment variable \code{YT_AUTH_FILE} to a valid file location,
#' the function will look there for authentication details.
#' Otherwise it will look in the working directory for the `.httr-oauth` file, which if not present
#' will trigger an authentication flow via Google login screen in your browser.
#'
#' If \code{YT_AUTH_FILE} is specified, then \code{gce_auth()} will be called upon loading the package
#' via \code{library(googleComputeEngineR)},
#' meaning that calling this function yourself at the start of the session won't be necessary.
#'
#' \code{YT_AUTH_FILE} can be either a token generated by \link[googleAuthR]{gar_auth} or
#' service account JSON ending with file extension \code{.json}
#'
#' @return Invisibly, the token that has been saved to the session
#' @import googleAuthR
#' @export
yt_auth <- function(new_user = FALSE, no_auto = FALSE){
required_scopes <- c("https://www.googleapis.com/auth/youtube",
"https://www.googleapis.com/auth/youtube.readonly",
"https://www.googleapis.com/auth/yt-analytics-monetary.readonly",
"https://www.googleapis.com/auth/yt-analytics.readonly")
googleAuthR::gar_auto_auth(required_scopes,
new_user = new_user,
no_auto = no_auto,
environment_var = "YT_AUTH_FILE")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.