As to my best knowledge, gmailr is using gargle in the background to manage authentifications. I went through documentation on gmailr and gargle on non-interactive authentification (e.g. https://gargle.r-lib.org/articles/get-api-credential) however fail to keep the functionality working longer than for a week (after week I need to authorize again interactively). Sadly gmair package community died out. How can I make the token discovery process in gargle to access the already available token(s)? I tried with using both ouath and service account token. The same time limited result.
Example of debug on when gargle wants to refresh token interactively
trying `token_fetch()`
trying `credentials_service_account()`
Error caught by `token_fetch()`:
Argument 'txt' must be a JSON string, URL or file.
trying `credentials_external_account()`
aws.ec2metadata not installed; can't detect whether running on EC2 instance
trying `credentials_app_default()`
trying `credentials_gce()`
trying `credentials_byo_oauth()`
Error caught by `token_fetch()`:
inherits(token, "Token2.0") is not TRUE
trying `credentials_user_oauth2()`
Gargle2.0 initialize
adding "userinfo.email" scope
loading token from the cache
no matching token in the cache
initiating new token
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
putting token into the cache:
I would like to non-interactively use the token via gargle and supply it directly to gmailr in the following manner:
if(GLOBALS$GMAIL_DEBUG == "ON") options(gargle_verbosity = "debug")
gmail_interface <- R6Class("gmail_interface",
public = list(
from = NULL,
to = NULL,
initialize = function(){
logdebug(private$path)
private$configure()
self$from <- '1234@gmail.com'
self$to <- c('xy@gmail.com', 'dew@web.de')
self$intro()
},
intro = function(){
cat(paste0("Initialized gmail interface with from: ", self$from, " to: ", self$to, ".\n"))
},
send = function(subject = sprintf("Automated eMail on %s", Sys.time()), text = "test"){
email <- gm_mime() %>%
gm_to(self$to) %>%
gm_from(self$from) %>%
gm_subject(subject) %>%
gm_text_body(text)
gm_send_message(email)
}
),
private = list(
path = file.path(path_current_script, "gmailR_cred"),
configure = function(){
JSON_FILE = list.files(private$path, pattern = 'json', full.names = TRUE)[1L]
gm_auth_configure(path = JSON_FILE)
SECRET = '.secretlocal'
gm_auth(email = "1234@gmail.com",
scopes = 'send',
cache = file.path(
private$path,
SECRET)
)
}
)
)