Forked from MarkEdmondson1234/google_calendar_demo.R
Last active
October 2, 2017 23:34
-
-
Save smach/ae92d7bb0d19f616406da8a8357280cf to your computer and use it in GitHub Desktop.
A demo of calling Google Calendar API
This file contains hidden or 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
library(googleAuthR) | |
## set scopes for calendar | |
options(googleAuthR.scopes.selected = "https://www.googleapis.com/auth/calendar.readonly", | |
googleAuthR.client_id = "XXXX", ## add your Google project client Id - find it at https://console.developers.google.com/apis/credentials then click on the appropriate OAuth 2.0 client ID | |
googleAuthR.client_secret = "XXXX") ## add your Google project client secret - at same place as above | |
## make sure calendar API is activated for your Google Project at below URL: | |
# https://console.cloud.google.com/apis/api/calendar-json.googleapis.com/overview | |
## this is taken and simplified from | |
# https://github.com/MarkEdmondson1234/autoGoogleAPI/blob/master/googlecalendarv3.auto/R/calendar_functions.R#L962 | |
#' Gets a list of events for calendarId | |
#' | |
#' @param calendarId The calendar to get. Default is primary for authenticated user | |
#' @return a big list of JSON | |
events.list <- function(calendarId = "primary") { | |
url <- sprintf("https://www.googleapis.com/calendar/v3/calendars/%s/events", | |
calendarId) | |
f <- googleAuthR::gar_api_generator(url, "GET", | |
data_parse_function = function(x) x) | |
f() | |
} | |
## --------- | |
# To use: | |
## authenticate with email that has access to the calendar | |
gar_auth() | |
## should kick you out to Google OAuth2 flow. Come back here when done.... | |
## get default (primary) calendar list | |
events <- events.list() | |
## events is raw JSON response, | |
## parse down to items by modifying the data_parse_function in events.list() | |
## or operating afterwards in code like below | |
events$items$summary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment