怎样通过GitHub API获取某个项目被Star的详细信息(时间,用户ID)

这个需求也比较明确,目前GitHub的页面上并不提供对某个项目Star随时间变化的数据,但实际上可以通过GitHub API获取,在之前的一篇日志中,我简单介绍了通过curl使用GitHub API的方法,不过正如这里介绍的:

Most applications will use an existing wrapper library in the language of your choice, but it's important to familiarize yourself with the underlying API HTTP methods first.

我们这里选择使用PyGitHub这个library:https://github.com/PyGithub/PyGithub

还是以bitcoin这个项目为例,要print出所有star的用户和具体时间,只需要下面这些代码:

from github import Github

g=Github("自己申请的Token")
repo=g.get_repo('bitcoin/bitcoin')
stargazers=repo.get_stargazers_with_dates()
for people in stargazers:
    print people.starred_at
    print people.user

实际上很简单,首先生成主类GitHub:http://pygithub.readthedocs.io/en/latest/github.html

再使用Repository这个class中的method:http://pygithub.readthedocs.io/en/latest/github_objects/Repository.html

就简单总结这么多。


猜你喜欢

转载自blog.csdn.net/qysh123/article/details/79782963