R/yadirGetToken.R

yadirGetToken <-
function(Login = NULL, TokenPath = getwd()){
  # open browser
  browseURL("https://oauth.yandex.ru/authorize?response_type=token&client_id=819b3e20723647708f95abd061f6515c")
  
  # create list
  token <- list(token_type    = "bearer",
                access_token  = readline(prompt = "Enter your token: "),
                expires_in    = 26715505,
                refresh_token = NA,
                expire_at     = Sys.time() + as.numeric(26715505, units = "secs"))
  # set class
  class(token) <- "yadir_token"
  
  # ask for save credential
  # save token in file
  message("Do you want save API credential in local file (",paste0(TokenPath, "/", Login, ".rymAuth.RData"),"), for use it between R sessions?")
  ans <- readline("y / n (recomedation - y): ")
  
  if ( tolower(ans) %in% c("y", "yes", "ok", "save") ) {
    # save into local file
    save(token, file = paste0(TokenPath, "/", Login, ".yadirAuth.RData"))
    message("Token saved in file ", paste0(TokenPath, "/", Login, ".yadirAuth.RData"))
  }
  return(token)
}
serditov/ryandexdirect documentation built on May 15, 2019, 12:09 a.m.