0

I have been trying to find a way to get a list of repos starred in a user's github profile. Most of the suggested solutions include using github's API as follows:

https://api.github.com/users/$GITHUB_USER$/repos

Most solutions use the above API in various forms such as in this post. However, what it gives is the repos that a user owns, which is different than the repos starred by the user. For instance, Kenneth Reitz owns 94 repos, while he has starred 1906 repos. So, if you run the code given below in python, names_repos will show you the repos he owns (94 in total) and not the ones he has starred (1906 in total):

import requests
import json

GITHUB_USER = "kennethreitz"

r = requests.get("https://api.github.com/users/" + GITHUB_USER + "/repos?per_page=100" )

names_repos = json.loads(r.text)

What I want instead is the list of starred repos (in a text or some other file), which can be seen here: https://github.com/stars/kennethreitz. However, it does not seem like the github API is able to provide that. I don't mind if there are any private repos that are not visible to others, but I would like to get a list of whatever repos I can see under the starred repos.

user11
  • 191
  • 1
  • 3
  • 11

1 Answers1

1

You need to use the starred endpoint. For getting the info about what the user has starred.

https://api.github.com/users/xxxxxx/starred?per_page=100
Example
https://api.github.com/users/kennethreitz/starred?per_page=100

You can see the list of api's available using the endpoint

https://api.github.com/users/xxxxx
example
https://api.github.com/users/kennethreitz/
karthick
  • 11,998
  • 6
  • 56
  • 88
  • Thanks! That is exactly what I was looking for. However, after a limit of `100` repos, if I try moving ahead to get remaining starred repos as [`starred?per_page=100\&page=2`](https://stackoverflow.com/a/33159888/8092075), `starred?per_page=100\&page=3`, and so forth, it only gives 30 per page. Am I doing it right? What is the appropriate way of grabbing full list of 1906 repositories? Thanks, again. – user11 Sep 21 '18 at 18:20
  • why the slash after per_page=100\ ? Most likely this is causing issue, https://api.github.com/users/kennethreitz/starred?per_page=100&page=2 visit this link directly, it still shows 100 entries – karthick Sep 21 '18 at 18:24
  • Yes, you are right. If you click on the link in my comment, you would see that the last comment under that answer suggested that format. Thanks so much. – user11 Sep 21 '18 at 18:34
  • @user11 I believe that is a typo – karthick Sep 21 '18 at 18:36
  • One quick (and related) question: is it possible to *star* github repositories programmatically? For instance, is it possible to *star* 100 repos with their known URLs using a code? – user11 Sep 21 '18 at 19:18
  • Yes. you have to authenticate first inorder to star the repos. You can refer the api here https://developer.github.com/v3/activity/starring/ – karthick Sep 21 '18 at 19:51
  • Thanks. This is helpful, but to be honest with you I have never done git coding, and I could not find how and where command `GET` is use through search. Perhaps, this is a git command and must be used in its environment? I would appreciate if you could throw some light on how to implement the commands to star repos, and if it makes sense to ask that in a new question then I could do that. – user11 Sep 21 '18 at 20:04
  • Yes please. Kindly post a new question, with what you have tried and where you are facing the issue. Api's are different from git command. If your use case is only to star repo's for your user account then you need to use a github api. – karthick Sep 21 '18 at 20:06