Skip to content

This is a rather magical function that calls a series of concrete credential-fetching functions, each wrapped in a tryCatch(). token_fetch() keeps trying until it succeeds or there are no more functions to try. See the vignette("how-gargle-gets-tokens") for a full description of token_fetch().


token_fetch(scopes = NULL, ...)



A character vector of scopes to request. Pick from those listed at

For certain token flows, the "" scope is unconditionally included. This grants permission to retrieve the email address associated with a token; gargle uses this to index cached OAuth tokens. This grants no permission to view or send email and is generally considered a low-value scope.


Additional arguments passed to all credential functions.


An httr::Token (often an instance of something that inherits from httr::Token) or NULL.

See also

cred_funs_list() reveals the current registry of credential-fetching functions, in order.

Other credential functions: credentials_app_default(), credentials_byo_oauth2(), credentials_external_account(), credentials_gce(), credentials_service_account(), credentials_user_oauth2()


if (FALSE) {
token_fetch(scopes = "")