Skip to content

Instantly share code, notes, and snippets.

@andyczerwonka
Forked from mGalarnyk/R_Github_Api.R
Created January 20, 2018 13:59
Show Gist options
  • Save andyczerwonka/85d47fcb5202ade0a7ed880b34ee7c56 to your computer and use it in GitHub Desktop.
Save andyczerwonka/85d47fcb5202ade0a7ed880b34ee7c56 to your computer and use it in GitHub Desktop.
Reading Data From GitHub API Using R. This code was originally for the John Hopkins Data Science Specialization. Blog on it https://medium.com/@GalarnykMichael/accessing-data-from-github-api-using-r-3633fb62cb08#.toufbbjgd
#install.packages("jsonlite")
library(jsonlite)
#install.packages("httpuv")
library(httpuv)
#install.packages("httr")
library(httr)
# Can be github, linkedin etc depending on application
oauth_endpoints("github")
# Change based on what you
myapp <- oauth_app(appname = "Coursera_John_Hopkins",
key = "8758a6bf9a146e1da0c1",
secret = "b9504edde46b794414495bd9c33ea28cbfd87824")
# Get OAuth credentials
github_token <- oauth2.0_token(oauth_endpoints("github"), myapp)
# Use API
gtoken <- config(token = github_token)
req <- GET("https://api.github.com/users/jtleek/repos", gtoken)
# Take action on http error
stop_for_status(req)
# Extract content from a request
json1 = content(req)
# Convert to a data.frame
gitDF = jsonlite::fromJSON(jsonlite::toJSON(json1))
# Subset data.frame
gitDF[gitDF$full_name == "jtleek/datasharing", "created_at"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment