scr_auth: Do OAuth2 authentication

Description Usage Arguments Details Multiple accounts Auto-authentication Your own Google Project Service accounts See Also

View source: R/auth.R

Description

Do OAuth2 authentication

Usage

1
scr_auth(token = NULL, email = NULL)

Arguments

token

Where you want to save the auth file, or an existing token or file location of a token to authenticate with

email

An email you have authenticated with previously

Details

Run this function first time to authenticate with Google in your browser.

After initial authentication, a sc.oauth will be saved to your working directory, where your authentication details are kept. Keep this file safe.

If you want to reauthenticate, delete this file from your directory or run scr_auth(new_user = TRUE)

Multiple accounts

You can authenticate with a new auth file for each account. Supply argument token with the name of the cache file you want to use e.g. scr_auth(token = "one.httr-oauth") for one account, scr_auth(token = "another.httr-oauth") for a different account.

Auto-authentication

You can choose to auto-authenticate by moving your sc.httr-oauth or by creating a Google OAuth service account JSON file.

Specify an environment variable in R via a .Renviron file or using Sys.setenv which point to the file location of your chosen authentication file. See Startup

Once you have set the environment variable SC_AUTH_FILE to a valid file location, the function will look there for authentication details upon loading the library meaning you will not need to call scr_auth() yourself as you would normally.

An example .Renviron file is below:

SC_AUTH_FILE = "/Users/bob/auth/sc.oauth"

SC_AUTH_FILE can be either a auth file for a token generated by gar_auth or service account JSON ending with file extension .json

Your own Google Project

Be default the Google Project used is shared by all users, this is usually sufficient, but you could choose to create your own Google Project and turn on the Webmaster APIs.

You can then download your own client JSON, and set by placing in the GAR_CLIENT_JSON environment argument. See gar_set_client for details.

Service accounts

If you use the service account JSON, you will need to add the service account email to your Search Console users to see data e.g. xxxx@yyyyyy.iam.gserviceaccount.com

See Also

gar_auth


searchConsoleR documentation built on Sept. 6, 2019, 5:02 p.m.