Skip to content

Instantly share code, notes, and snippets.

@CleverProgrammer
Created April 30, 2016 03:54
Show Gist options
  • Save CleverProgrammer/e049ddeff599ab36088e7782fe6f4126 to your computer and use it in GitHub Desktop.
Save CleverProgrammer/e049ddeff599ab36088e7782fe6f4126 to your computer and use it in GitHub Desktop.
Oauth Github Application R
library(httr)
require(httpuv)
require(jsonlite)
# 1. Find OAuth settings for github:
# http://developer.github.com/v3/oauth/
oauth_endpoints("github")
# 2. To make your own application, register at at
# https://github.com/settings/applications. Use any URL for the homepage URL
# (http://github.com is fine) and http://localhost:1410 as the callback url
#
# Replace your key and secret below.
myapp <- oauth_app("not_github",
key = "",
secret = "")
# 3. Get OAuth credentials
# github_token <- oauth2.0_token(oauth_endpoints("github"), myapp)
# 4. Use API
gtoken <- config(token = github_token)
ratio <- function(language, username) {
req <- GET(paste("https://api.github.com/users/", username, "/repos", sep = ""), gtoken)
stop_for_status(req)
# print(content(req)[[1]]$id)
repositories <- 0
how_many_r <- 0
for (i in content(req)) {
repositories <- repositories + 1
# print(i[['language']])
if (!is.null(i[['language']])){
if (i[['language']] == language) {
how_many_r <- how_many_r + 1
}
}
# print(i[['name']])
# print(i[['created_at']])
# print('')
}
print(how_many_r)
print(repositories)
print(how_many_r / repositories)
}
ratio("Python", "Qazipython")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment