Skip to content

Instantly share code, notes, and snippets.

@artemklevtsov
Last active August 29, 2015 14:17
Show Gist options
  • Save artemklevtsov/781cb8440ccf8ef05e9c to your computer and use it in GitHub Desktop.
Save artemklevtsov/781cb8440ccf8ef05e9c to your computer and use it in GitHub Desktop.
Shiny Google OAuth example
library(httr)
endpoint <- oauth_endpoints("google")
app <- oauth_app(appname = "my_app",
key = "my_key",
secret = "my_secret")
scope <- "https://www.googleapis.com/auth/analytics.readonly"
redirect_uri <- "http://shinyapps.io/my_nickname/my_qpp"
authorize_url <- modify_url(endpoint$authorize, query = list(
client_id = app$key,
scope = scope,
redirect_uri = redirect_uri,
response_type = "code"))
get_creds <- function(code) {
req <- POST(endpoint$access, encode = "form",
body = list(
client_id = app$key,
client_secret = app$secret,
redirect_uri = redirect_uri,
grant_type = "authorization_code",
code = code))
return(content(req))
}
params <- list(scope = scope, as_header = TRUE)
token <- Token2.0$new(app = app, endpoint = endpoint, params = params, credentials = credentials, cache_path = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment