如何有效地调用github API以提取多个回购贡献者的真实姓名

时间:2019-02-27 18:21:18

标签: r json github

我想获取所有贡献者的真实姓名到github repos列表中。我可以做到,但是需要对github API进行一系列循环调用。如果我想这样做,请说前100个R包,我的方法将需要2100次对API的调用(假设每个回购有20个贡献者)。如果我不足以评估贡献者的数量,那么我可能会达到授权用户的速率限制。我想知道是否有一种方法需要较少的API调用。以下是我认为的“硬”方法。此示例仅从一个回购中获得一名贡献者进行说明,而无需遍历列表。

library(dplyr)
library(jsonlite)

#this would actually be a list of multiple repos
repo_name <- "dplyr"
# we don't know the github username associated with the package so construct a search
# to get the most likely candidate
search_url <- paste0("https://api.github.com/search/repositories?q=",
                     repo_name,
                     ".%20is:name+language:r&sort=stars&order=desc")


# first api call.  would need to would need to loop/map/apply over multiple contributors repo names
all_repos<-jsonlite::read_json(search_url,simplifyVector = TRUE)
# assume first repo is target.  Hope so.
target_repo<-all_repos$items$full_name[1]
search_url <- paste0("https://api.github.com/repos/",
                     target_repo,
                     "/contributors")
#second api call
contributors <- jsonlite::read_json(search_url,simplifyVector = TRUE)

#third api call. would need to loop/map/apply over multiple contributors
real_name <- jsonlite::read_json(contributors$url[1])$name
real_name
#> [1] "Romain François"

谢谢。

0 个答案:

没有答案