1. 程式人生 > >怎樣通過GitHub API獲取某個專案被Star的詳細資訊(時間,使用者ID)

怎樣通過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.

還是以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

就簡單總結這麼多。