Reputation: 2143
I've been using the GET /repos/:owner/:repo/stargazers
endpoint, but I've noticed that it only provides 30 stargazers, which isn't enough for my purposes now. I've switched to the search API, GET /search/repositories?q=:repo
(items[0].stargazers_count
), but what if someone creates 20 repos with the same name? I'd have to make more than one request. Is there a better way?
Upvotes: 0
Views: 3762
Reputation: 28805
The /repos/:owner/:repo/stargazers
endpoint is paginated. You can get all of the stargazers from that endpoint quickly and easily. For example, if you were to use github3.py it would be 3 lines:
import github3
repo = github3.repository(':owner', ':repo')
stargazers = list(repo.stargazers())
This however cannot be done in a single request (which is why it's paginated).
Using the search API is probably the cheapest, but your concern about a single person having 20 repositories with the same name is not sensible. A single user can only have one repository with a specific name. That, however, shouldn't be considered a guarantee that there won't be more than one result so you should probably use a different query string, e.g.,
import github3
github3.search_repositories('repo:owner/repo_name')
Which should translate roughly to
GET /search/repositories?q=repo%3Aowner%2Frepo_name
Upvotes: 5