I'm trying to send emails in a non-interactive session via a service account using gmailr
. I've granted domain-wide authority for the service account and enabled the Gmail, Calendar, and Drive APIs, and a few others. There's a chance I don't have the right scopes for the domain wide authority, but I couldn't find a list of required ones. Anyone have any experience with this error or troubleshooting this?
Code below:
library(gmailr)
library(gargle)
options(gargle_verbosity = "debug")
gm_auth(email = "me@gmail.org",
path = Sys.getenv('service_account_json'))
# trying `token_fetch()`
# Trying `credentials_byo_oauth()` ...
# Error caught by `token_fetch()`:
# inherits(token, "Token2.0") is not TRUE
# trying `credentials_service_account()`
# adding "userinfo.email" scope
# service account email: my_service_account@my_service_account-1234.iam.gserviceaccount.com
gm_profile(user_id = "me", verbose = TRUE)
error message:
# Error in gmailr_GET("profile", user_id, class = "gmail_profile") :
# Gmail API error: 400
# Precondition check failed.