Last active
September 10, 2015 12:00
-
-
Save MansMeg/bbfadc771cb15b56b4cd to your computer and use it in GitHub Desktop.
Download private files from github
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
#' Download a (private) file from github using a personal access token | |
#' | |
#' @description | |
#' Download a file from a private repository using GitHub API v3. | |
#' | |
#' @param repo Repository as :owner/:repo | |
#' @param path Path to file | |
#' @param pat Personal access token | |
#' | |
#' @details | |
#' Do never write down your access token in the code. Use envirnomental variables or config files. | |
#' | |
get_github_file <- function(repo, path, pat){ | |
auth <- httr::authenticate(pat, "x-oauth-basic", "basic") | |
req <- httr::GET("https://api.github.com", | |
path = paste0("repos/",repo,"/contents/",path), auth) | |
httr::stop_for_status(req) | |
req_file <- httr::GET(httr::content(req, as="parsed")$download_url) | |
httr::stop_for_status(req_file) | |
httr::content(req_file, as="parsed") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment