Authorize googledrive to view and manage your Drive files. By default, you are directed to a web browser, asked to sign in to your Google account, and to grant googledrive (the tidyverse, actually) permission to operate on your behalf with Google Drive. By default, these user credentials are cached in a file named .httr-oauth in the current working directory, from where they can be automatically refreshed, as necessary.

drive_auth(oauth_token = NULL, service_token = NULL, reset = FALSE,
  cache = getOption("httr_oauth_cache"),
  use_oob = getOption("httr_oob_default"), verbose = TRUE)



Optional; path to an .rds file with a previously stored OAuth token.


Optional; a JSON string, URL, or path, giving or pointing to the service token file.


Logical, defaults to FALSE. Set to TRUE if you want to forget any token previously used in this session and start afresh. Disables the .httr-oauth file in current working directory by renaming to .httr-oauth-SUSPENDED.


A logical value or a string. TRUE means to cache using the default cache file .httr-oauth, FALSE means don't cache, and NA means to guess using some sensible heuristics. A string mean use the specified path as the cache file.


if FALSE, use a local webserver for the OAuth dance. Otherwise, provide a URL to the user and prompt for a validation code. Defaults to the of the "httr_oob_default" default, or TRUE if httpuv is not installed.


Logical, indicating whether to print informative messages (default TRUE).


Most users, most of the time, do not need to call drive_auth() explicitly -- it is triggered by the first action that requires authorization. Even when called, the default arguments will often suffice. However, when necessary, this function allows the user to

  • force the adoption of a new token, via reset = TRUE

  • retrieve current token, e.g., for storage to an .rds file

  • put a pre-existing OAuth or service account token into force

  • prevent the caching of new, interactively-obtained credentials in .httr-oauth

For even deeper control over auth, use drive_auth_config() to use your own OAuth app or API key. drive_auth_config() also allows you to deactivate auth, sending only an API key in requests, which works if you only need to access public data.

See also

More detail is available from Using OAuth 2.0 for Installed Applications

Other auth functions: drive_auth_config, drive_deauth


## load/refresh existing credentials, if available
## otherwise, go to browser for authentication and authorization

## force a new oauth token to be obtained
drive_auth(reset = TRUE)

## store token in an object and then to file
ttt <- drive_auth()
saveRDS(ttt, "ttt.rds")

## load a pre-existing token
drive_auth("ttt.rds") # from .rds file

## use a service account token
drive_auth(service_token = "foofy-83ee9e7c9c48.json")
# }