authorize: Authorize the RGA package to the user's Google Analytics...

Description Usage Arguments Details Value Use custom Client ID and Client secret Revoke access application References See Also Examples

Description

authorize() function uses oauth2.0_token to obtain the OAuth tokens. Expired tokens will be refreshed automamaticly. If you have no client.id and client.secret the package provides predefined values.

Usage

1
2
3
4
authorize(username = getOption("rga.username"),
  client.id = getOption("rga.client.id"),
  client.secret = getOption("rga.client.secret"),
  cache = getOption("rga.cache"), new.auth = FALSE)

Arguments

username

character. Google username email address hint. If not set you will need choose an account for the authorization.

client.id

character. OAuth client ID. If you set the environment variable RGA_CLIENT_ID it is used.

client.secret

character. OAuth client secret. If you set the environment variable RGA_CLIENT_SECRET it is used.

cache

logical or character. TRUE means to cache using the default cache file .oauth-httr, FALSE means not to cache. A string means to use the specified path as the cache file. Otherwise will be used the rga.cache option value (.ga-token.rds by default). If username argument specified token will be cached in the .username-token.rds file.

new.auth

logical. Set TRUE to reauthorization with the same or different Google Analytics account.

Details

After calling this function first time, a web browser will be opened. First, log in with a Google Account, confirm the authorization to access the Google Analytics data. Note that the package requests access for read-only data.

When the authorize() function is used the GAToken variable is created in the separate TokenEnv environment which is not visible for user. So, there is no need to pass the token argument to any function which requires authorization every time. Also there is a possibility to store token in separate variable and to pass it to the functions. It can be useful when you are working with several accounts at the same time.

username, client.id, client.secret and cache params can be specified by an appropriate options (with “rga” prefix).

Value

A Token2.0 object containing all the data required for OAuth access.

Use custom Client ID and Client secret

For some reasons you may need to use a custom client ID and client secret. In order to obtain these, you will have to register an application with the Google Analytics API. To find your project's client ID and client secret, do the following:

  1. Go to the Google Developers Console.

  2. Select a project (create if needed).

  3. Select APIs & auth in the sidebar on the left.

  4. In the list of APIs select Analytics API. Then click Enable API.

  5. Select Credentials in the sidebar on the left.

  6. To set up a service account select Create New Client ID. Select Installed Application and Others options and then select Create Client ID.

You can return to the Google Developers Console at any time to view the client ID and client secret on the Client ID for native application section on Credentials page.

There 3 ways to use custom Client ID and Client secret:

  1. Pass the client.id and client.secret arguments directly in the authorize() function call

  2. Set the RGA_CLIENT_ID and RGA_CLIENT_SECRET environment variables

  3. Set the rga.client.id and rga.client.secret options

Revoke access application

To revoke access the RGA package do the following:

  1. Go to the Apps connected to your account page

  2. Find RGA package entry. Then click on it

  3. Click on the Revoke access button in the sidebar on the right

References

Google Developers Console

Environment variable

See Also

Other OAuth: oauth_app oauth2.0_token Token-class

To revoke all tokens: revoke_all

Setup environment variables: Startup

Examples

1
2
3
4
5
6
7
8
## Not run: 
authorize(client.id = "my_id", client.secret = "my_secret")
# if set RGA_CLIENT_ID and RGA_CLIENT_SECRET environment variables
authorize()
# assign token to variable
ga_token <- authorize(client.id = "my_id", client.secret = "my_secret")

## End(Not run)

jdeboer/RGA-1 documentation built on May 18, 2019, 11:29 p.m.