-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auth is working for github, google, and calendly!
- Loading branch information
Showing
15 changed files
with
128 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
^renv\.lock$ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ | ||
^\.httr-oauth$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
.RData | ||
.Ruserdata | ||
.DS_Store | ||
.secrets/* | ||
.secrets/* | ||
.httr-oauth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Package: metricminer2 | ||
Package: metricminer | ||
Type: Package | ||
Title: What the Package Does (Title Case) | ||
Version: 0.1.0 | ||
|
@@ -7,5 +7,12 @@ Maintainer: The package maintainer <[email protected]> | |
Description: More about what it does (maybe more than one line) | ||
Use four spaces when indenting paragraphs within the Description. | ||
License: What license is it under? | ||
BugReports: https://github.com/datatrail-jhu/rgoogleclassroom/issues | ||
Imports: | ||
attempt, | ||
curl, | ||
httr, | ||
jsonlite | ||
Encoding: UTF-8 | ||
RoxygenNote: 7.2.3 | ||
LazyData: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1 @@ | ||
remotes::install_github("MarkEdmondson1234/googleAnalyticsR") | ||
|
||
library(tidyverse) | ||
library(here) | ||
library(googleAnalyticsR) | ||
library(jsonlite) | ||
|
||
ga_auth() | ||
account_df <- ga_accounts() | ||
|
||
account_df$id | ||
|
||
## View account_list and pick the viewId you want to extract data from. | ||
ga_id <- account_df$id[2] | ||
|
||
ga_webproperty_list(ga_id) | ||
|
||
## simple query to test connection, get 10 rows | ||
google_analytics(ga_id, | ||
date_range = c("2021-01-01", lubridate::today()), | ||
metrics = "sessions", | ||
dimensions = "date", | ||
max = 10 | ||
) | ||
|
||
|
||
# Ideally these Property IDs would get pulled from the API using the package, | ||
# but I can't figure out how to get them to show up. See the README.md for this | ||
# repo for more information. | ||
|
||
here("app", "data", "ga-properties.json") |> | ||
read_json() |> | ||
pluck("properties") |> | ||
bind_rows() |> | ||
select(name, displayName) |> | ||
mutate(name = gsub("properties/", "", name)) |> | ||
rename(ID = name, Property = displayName) |> | ||
select(Property, ID) |> | ||
mutate(GA = map(ID, ga_data, | ||
metrics = c("activeUsers", "sessions"), | ||
dimensions = c("date", "pagePath", "pageTitle"), | ||
date_range = c("2022-01-01", as.character(Sys.Date())), | ||
limit = -1 | ||
)) %>% | ||
unnest(GA) %>% | ||
write_csv(here("app", "data", "ga.csv")) | ||
# Extracting data from Google Analytics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,31 @@ | ||
remotes::install_github("MarkEdmondson1234/googleAnalyticsR") | ||
# Extracting data from Google Forms | ||
|
||
library(tidyverse) | ||
library(here) | ||
library(googleAnalyticsR) | ||
library(jsonlite) | ||
|
||
ga_auth() | ||
account_df <- ga_accounts() | ||
get_drive_file_list <- function(drive_id) { | ||
# Get endpoint url | ||
url <- get_endpoint("googledrive.endpoint") | ||
|
||
account_df$id | ||
# Get auth token | ||
token <- get_token("google") | ||
config <- httr::config(token = token) | ||
|
||
## View account_list and pick the viewId you want to extract data from. | ||
ga_id <- account_df$id[2] | ||
# Wrapping body parameters in a requests list | ||
body_params <- list( | ||
corpora = "drive", | ||
driveId = drive_id, | ||
includeItemsFromAllDrives = "true", | ||
supportsAllDrives = "true" | ||
) | ||
|
||
ga_webproperty_list(ga_id) | ||
# Get list of topics | ||
result <- httr::GET(url, config = config, body = body_params, accept_json()) | ||
|
||
## simple query to test connection, get 10 rows | ||
google_analytics(ga_id, | ||
date_range = c("2021-01-01", lubridate::today()), | ||
metrics = "sessions", | ||
dimensions = "date", | ||
max = 10 | ||
) | ||
if (httr::status_code(result) != 200) { | ||
httr::stop_for_status(result) | ||
} | ||
|
||
|
||
# Ideally these Property IDs would get pulled from the API using the package, | ||
# but I can't figure out how to get them to show up. See the README.md for this | ||
# repo for more information. | ||
|
||
here("app", "data", "ga-properties.json") |> | ||
read_json() |> | ||
pluck("properties") |> | ||
bind_rows() |> | ||
select(name, displayName) |> | ||
mutate(name = gsub("properties/", "", name)) |> | ||
rename(ID = name, Property = displayName) |> | ||
select(Property, ID) |> | ||
mutate(GA = map(ID, ga_data, | ||
metrics = c("activeUsers", "sessions"), | ||
dimensions = c("date", "pagePath", "pageTitle"), | ||
date_range = c("2022-01-01", as.character(Sys.Date())), | ||
limit = -1 | ||
)) %>% | ||
unnest(GA) %>% | ||
write_csv(here("app", "data", "ga.csv")) | ||
# Process and return results | ||
result_content <- content(result, "text") | ||
result_list <- fromJSON(result_content) | ||
return(result_list) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Extracting data from Google Sheets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,20 @@ | ||
# Scopes | ||
|
||
|
||
find_scopes <- function(endpoint) { | ||
|
||
|
||
find_scopes <- function(app_name) { | ||
### Declare all the scopes | ||
forms_scopes_list <- c( | ||
"https://www.googleapis.com/auth/drive", | ||
"https://www.googleapis.com/auth/drive.file", | ||
"https://www.googleapis.com/auth/drive.readonly", | ||
"https://www.googleapis.com/auth/drive.metadata.readonly", | ||
"https://www.googleapis.com/auth/forms.body", | ||
"https://www.googleapis.com/auth/forms.body.readonly", | ||
"https://www.googleapis.com/auth/forms.responses.readonly" | ||
scopes <- list( | ||
google = c( | ||
"https://www.googleapis.com/auth/drive", | ||
"https://www.googleapis.com/auth/drive.file", | ||
"https://www.googleapis.com/auth/drive.readonly", | ||
"https://www.googleapis.com/auth/drive.metadata.readonly", | ||
"https://www.googleapis.com/auth/forms.body", | ||
"https://www.googleapis.com/auth/forms.body.readonly", | ||
"https://www.googleapis.com/auth/forms.responses.readonly" | ||
), | ||
github = c("repo") | ||
) | ||
|
||
base_classroom_uri <- "https://www.googleapis.com/auth/classroom." | ||
|
||
classroom_scopes_list <- paste0( | ||
base_classroom_uri, | ||
c( | ||
"courses", | ||
"courses.readonly", | ||
"topics", | ||
"topics.readonly", | ||
"profile.emails", | ||
"profile.photos", | ||
"rosters", | ||
"rosters.readonly", | ||
"announcements", | ||
"announcements.readonly", | ||
"course-work.readonly", | ||
"student-submissions.students.readonly", | ||
"student-submissions.me.readonly", | ||
"coursework.me", | ||
"courseworkmaterials", | ||
"coursework.students", | ||
"courseworkmaterials", | ||
"coursework.students.readonly", | ||
"coursework.me.readonly", | ||
"addons.student", | ||
"push-notifications", | ||
"addons.teacher", | ||
"rosters", | ||
"profile.emails" | ||
) | ||
) | ||
return(scopes[app_name]) | ||
} |
Oops, something went wrong.