gpt4 book ai didi

R - curl Github API 访问私有(private)仓库

转载 作者:行者123 更新时间:2023-12-01 13:42:12 25 4
gpt4 key购买 nike

我想做的就是阅读我组织私有(private) repo 中的所有 repo 和问题。我可以从我的 Windows 7 cmd.exe 执行

curl -u "user:pass" https://api.github.com/orgs/:org/repos

然后我取回了我所有的存储库。我可以将其通过管道传输到文件中:

curl -u "user:pass" https://api.github.com/orgs/:org/repos > "C:\Users\Location\file.txt"

这将保存 JSON 输出。我可以在 R 中复制它,但以一种看起来很糟糕的方式。

fullRepos = system('curl -s -u "user:pass" -G https://api.github.com/orgs/:org/repos',
intern=T,show.output.on.console = F)

这会捕获输出 (intern = T),-s 会去掉进度条,这样我就可以折叠线条并将其转换为数据框。这将取回所有存储库,包括公共(public)和私有(private)存储库。

我尝试使用 RCurl 来做同样的事情,但下面的代码只提供了公共(public)存储库。 httpheader 是因为否则 API 会拒绝我的调用。

RCurl::getURL(url="https://api.github.com/orgs/:org/repos",userpwd ="user:pass",
httpheader = c('User-Agent' = "A user agent"))

我也尝试过 httr,它也只提供公共(public)存储库。

httr::GET(url="https://api.github.com/orgs/:org/repos",userpwd="user:pass")

RCurlhttr 我做错了什么?我宁愿有一个不生成系统命令然后将这些行粘贴在一起的工作流。

最佳答案

我们可以使用 httr 中的 authenticate() 辅助函数来为我们构建身份验证 header ,而无需手动创建它。此外,verbose() 可用于调试 HTTP 问题:

httr::GET(url="https://api.github.com/orgs/:‌​org/repos",
httr::authenticate("user", "pass"),
httr::verbose())

关于R - curl Github API 访问私有(private)仓库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39104968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com