Do OAuth2 authentication
scr_auth(token = NULL, email = NULL)
Where you want to save the auth file, or an existing token or file location of a token to authenticate with
An email you have authenticated with previously
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.
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
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.
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
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)