-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrga_initiate_API_connection.R
34 lines (30 loc) · 1.43 KB
/
rga_initiate_API_connection.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#### Adapted from http://randyzwitch.com/r-google-analytics-api/
#### Connecting to Google Analytics API via R
#### Uses OAuth 2.0
#### https://developers.google.com/analytics/devguides/reporting/core/v3/ for documentation
# Install devtools package & rga - This is only done one time
install.packages("devtools")
library(devtools)
install_github("rga", "skardhamar")
install.packages("ggplot2")
# Load rga package - requires bitops, RCurl, rjson
# Load lubridate to handle dates
library(rga)
library(lubridate)
# library(ProjectTemplate)
library("ggplot2")
setwd('C:/Users/m.parzakonis/Google Drive/MyCodeRants/GA/src')
# Authenticating to GA API. Go to https://code.google.com/apis/console/ and create
# an API application. Don't need to worry about the client id and shared secret for
# this R code, it is not needed
# setwd('GA')
# load.project()
# If file listed in "where" location doesn't exist, browser window will open.
# Allow access, copy code into R console where prompted
# Once file located in "where" directory created, you will have continous access to
# API without needing to do browser authentication
# The next line is to cure the well known issue with rCurl, should be fixed in the next release
options(RCurlOptions = list(verbose = FALSE, capath = system.file("CurlSSL", "cacert.pem", package = "RCurl"), ssl.verifypeer = FALSE))
rga.open(instance = "ga", where = "~/Documents/R/ga-api")
# Check that you do made a connection
ga$status()