Learn R Programming

googlesheets4 (version 0.1.0)

sheets_auth_configure: Edit and view auth configuration

Description

These functions give more control over and visibility into the auth configuration than sheets_auth() does. sheets_auth_configure() lets the user specify their own:

  • OAuth app, which is used when obtaining a user token.

  • API key. If googlesheets4 is de-authorized via sheets_deauth(), all requests are sent with an API key in lieu of a token. See the vignette How to get your own API credentials for more. If the user does not configure these settings, internal defaults are used. sheets_oauth_app() and sheets_api_key() retrieve the currently configured OAuth app and API key, respectively.

Usage

sheets_auth_configure(app, path, api_key)

sheets_api_key()

sheets_oauth_app()

Arguments

app

OAuth app, in the sense of httr::oauth_app().

path

JSON downloaded from Google Cloud Platform Console, containing a client id (aka key) and secret, in one of the forms supported for the txt argument of jsonlite::fromJSON() (typically, a file path or JSON string).

api_key

API key.

Value

  • sheets_auth_configure(): An object of R6 class gargle::AuthState, invisibly.

  • sheets_oauth_app(): the current user-configured httr::oauth_app().

  • sheets_api_key(): the current user-configured API key.

See Also

Other auth functions: sheets_auth(), sheets_deauth()

Examples

Run this code
# NOT RUN {
# see and store the current user-configured OAuth app (probaby `NULL`)
(original_app <- sheets_oauth_app())

# see and store the current user-configured API key (probaby `NULL`)
(original_api_key <- sheets_api_key())

if (require(httr)) {
  # bring your own app via client id (aka key) and secret
  google_app <- httr::oauth_app(
    "my-awesome-google-api-wrapping-package",
    key = "YOUR_CLIENT_ID_GOES_HERE",
    secret = "YOUR_SECRET_GOES_HERE"
  )
  google_key <- "YOUR_API_KEY"
  sheets_auth_configure(app = google_app, api_key = google_key)

  # confirm the changes
  sheets_oauth_app()
  sheets_api_key()

  # bring your own app via JSON downloaded from Google Developers Console
  # this file has the same structure as the JSON from Google
  app_path <- system.file(
    "extdata", "fake-oauth-client-id-and-secret.json",
    package = "googlesheets4"
  )
  sheets_auth_configure(path =app_path)

  # confirm the changes
  sheets_oauth_app()
}

# restore original auth config
sheets_auth_configure(app = original_app, api_key = original_api_key)
# }

Run the code above in your browser using DataLab