knitr::opts_chunk$set(echo = TRUE, comment = " ##", error = TRUE, collapse = TRUE) load_all() library("ggmap")
# keep secret, stored in ~/.Renviron the_key <- Sys.getenv("API_KEY_MAPS") # from github issues page, do this: options(ggmap = list(google = list(second_limit = 50L, day_limit = 2500))) ggmap::register_google(key=the_key)
us <- c(left = -125, bottom = 25.75, right = -67, top = 49) ggmap::get_stamenmap(us, zoom = 5, maptype = "toner-lite") %>% ggmap::ggmap()
if (F) { # remove old .httr-oauth (till I know what I am doing) file.remove(".httr-oauth") } # be sure enabled base::options("httr_oauth_cache" = TRUE) # https://developers.google.com/accounts/docs/OAuth2InstalledApp httr::oauth_endpoints("google")
# Security: key & secret are in ~/.Renviron ( do not push to github ) # NOTE: google calls this key as "Client ID" myapp <- httr::oauth_app("google", key <- Sys.getenv("OAUTH2_ID"), secret <- Sys.getenv("OAUTH2_SECRET") ) key <- Sys.getenv("OAUTH2_ID") key myapp
# scope = c("https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/youtube", # manage "https://www.googleapis.com/auth/youtube.readonly", "https://www.googleapis.com/auth/youtube.force-ssl" ) ``` ## Get auth.code | token .... ```r # NO .httr-oauth? # THEN pop, asks users, AND warns not verified, not safe # if option("httr_oauth_cache") was set to TRUE , token will then know to store # in .httr-oauth auth.code <- httr::oauth2.0_token( endpoint = httr::oauth_endpoints("google"), app = myapp, #cache = getOption("httr_oauth_cache"), cache = T, scope = scope ) auth.code
x <- readRDS(".httr-oauth") x names(x) length(x)
file <- "" file <- basename(file) dir <- "rmd" jimTools::ren_pdf(file,dir) jimTools::ren_github(file, dir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.