-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub-api-access.R
More file actions
26 lines (22 loc) · 974 Bytes
/
github-api-access.R
File metadata and controls
26 lines (22 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
library(httr)
# 1. Find OAuth settings for github:
# http://developer.github.com/v3/oauth/
oauth_endpoints("github")
# 2. Register an application at https://github.com/settings/applications;
# Use any URL you would like for the homepage URL (http://github.com is fine)
# and http://localhost:1410 as the callback url
#
# Insert your client ID and secret below - if secret is omitted, it will
# look it up in the GITHUB_CONSUMER_SECRET environmental variable.
client_id <- "eab8cda46b0f0d727488"
client_secret <- "a1c8ad7189af192063e5ecc938f0e295e856510f"
myapp <- oauth_app("github", client_id, secret=client_secret)
# 3. Get OAuth credentials
github_token <- oauth2.0_token(oauth_endpoints("github"), myapp)
# 4. Use API
gtoken <- config(token = github_token)
req <- GET("https://api.github.com/users/jtleek/repos", gtoken)
stop_for_status(req)
c <- content(req)
reponames <- sapply(c, function(x) x$name)
c[[match("datasharing", reponames)]]$created_at