Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of trending github repositories by github api?

Tags:

github-api

I want get list of github trending repos like this -https://github.com/trending?l=java but i didnt find any similar request methods at https://developer.github.com/v3/ , how can i get json responce with trending repos?

like image 974
Lester Avatar asked May 29 '15 08:05

Lester


People also ask

How do I see all repositories in GitHub?

To search the code in all repositories owned by a certain user or organization, you can use the user or org qualifier. To search the code in a specific repository, you can use the repo qualifier.

How do I get the latest tag from GitHub API?

GitHub doesn't have an API to retrieve the latest tag, as it has for retrieving the latest release. That might be because tags could be arbitrary strings, not necessarily semvers, but it's not really an excuse, since tags have timestamps, and GitHub does sort tags lexicographically when returning them via its Tags API.


1 Answers

GitHub seems to use their API to write the trending page and don't present it back as a particular API. You need to use the Repository Search API. I've followed the examples on this page, which could solve your needs by:

# We'll use the `date` command to get the date for "7 days ago" $ date -v-7d '+%Y-%m-%d' # => 2013-07-15  curl -G https://api.github.com/search/repositories --data-urlencode "sort=stars" --data-urlencode "order=desc" --data-urlencode "q=language:java"  --data-urlencode "q=created:>`date -v-7d '+%Y-%m-%d'`" 

And then go from there. You can also make your life a lot easier by installing jq on OS X or other platforms to get prettier output:

curl -G https://api.github.com/search/repositories --data-urlencode "sort=stars" --data-urlencode "order=desc" --data-urlencode "q=language:java"  --data-urlencode "q=created:>`date -v-7d '+%Y-%m-%d'`" | jq ".items[0,1,2] | {name, description, language, watchers_count, html_url}"   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                  Dload  Upload   Total   Spent    Left  Speed   0     0    0     0    0     0      0      0 --:--:-- --:--:-- -- 77  161k   77  125k    0     0   131k      0  0:00:01 --:--:--  0100  161k  100  161k    0     0   163k      0 --:--:-- --:--:-- --:--:--  163k {   "name": "vibrant.js",   "description": "Extract prominent colors from an image. JS port of Android's Palette.",   "language": "JavaScript",   "watchers_count": 1466,   "html_url": "https://github.com/jariz/vibrant.js" } {   "name": "JSPatch",   "description": "JSPatch bridge Objective-C and JavaScript using the Objective-C runtime. You can call any Objective-C class and method in JavaScript by just including a small engine.",   "language": "Objective-C",   "watchers_count": 830,   "html_url": "https://github.com/bang590/JSPatch" } {   "name": "KRVideoPlayer",   "description": "类似Weico的播放器,支持竖屏模式下全屏播放",   "language": "Objective-C",   "watchers_count": 524,   "html_url": "https://github.com/36Kr-Mobile/KRVideoPlayer" } 
like image 95
mbb Avatar answered Sep 26 '22 08:09

mbb