Learn R Programming

googleAuthR (version 0.1.0)

gar_auth: Authorize googleAuthR

Description

Authorize googleAuthR to access your Google user data. You will be directed to a web browser, asked to sign in to your Google account, and to grant googleAuthR access to user data for Google Search Console. 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.

Usage

gar_auth(token = NULL, new_user = FALSE, verbose = TRUE)

Arguments

token
an actual token object or the path to a valid token stored as an .rds file
new_user
logical, defaults to FALSE. Set to TRUE if you want to wipe the slate clean and re-authenticate with the same or different Google account. This deletes the .httr-oauth file in current working directory.
verbose
Increase feedback messages of the function.

Value

  • an OAuth token object, specifically a Token2.0, invisibly

Details

Most users, most of the time, do not need to call this function explicitly -- it will be 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

  • store a token -- the token is invisibly returned and can be assigned to an object or written to an.rdsfile
  • read the token from an.rdsfile or pre-existing object in the workspace
  • provide your own app key and secret -- this requires setting up a new project inhttps://console.developers.google.com{Google Developers Console}
  • prevent caching of credentials in.httr-oauth

In a call to scr_auth, the user can provide the token, app key and secret explicitly and can dictate whether credentials will be cached in .httr_oauth. If unspecified, these arguments are controlled via options, which, if undefined at the time googleAuthR is loaded, are defined like so:

[object Object],[object Object],[object Object]

To override these defaults in persistent way, predefine one or more of them with lines like this in a .Rprofile file: options(googleAuthR.client_id = "FOO", googleAuthR.client_secret = "BAR", googleAuthR.httr_oauth_cache = FALSE) See Startup for possible locations for this file and the implications thereof.

More detail is available from https://developers.google.com/identity/protocols/OAuth2{Using OAuth 2.0 to Access Google APIs}. This function executes the "installed application" flow.