Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Search API only return 30 results

Tags:

github-api

https://api.github.com/search/issues?q=stress+test+label:bug+language:python+state:closed

the above query is suppose to return 76 results, and when I try to run it, it only returns 30. I guess GitHub return results in portions when it is over 30. Any idea how I can get the rest of the results?

like image 611
Jack Feng Avatar asked Jun 05 '15 01:06

Jack Feng


People also ask

How many searches are allowed per minute for an unauthorized user searching on GitHub?

The Search API has a custom rate limit. For requests using Basic Authentication, OAuth, or client ID and secret, you can make up to 30 requests per minute. For unauthenticated requests, the rate limit allows you to make up to 10 requests per minute.

What does GitHub API return?

GitHub's API, by default, is set to return the first 30 repos for that particular user in alphabetical order.

What is PyGithub?

PyGithub is a Python library to use the Github API v3. With it, you can manage your Github resources (repositories, user profiles, organizations, etc.) from Python scripts.


2 Answers

You need to use page parameter, e.g. for next 30 page = 2

https://api.github.com/search/issues?q=stress+test+label:bug+language:python+state:closed&page=2 

You can also use per_page parameter to change the default size of 30. It supports max size of 100. Like this:

https://api.github.com/search/issues?q=stress+test+label:bug+language:python+state:closed&per_page=100 

More detail can be found here

like image 170
TheCodingFrog Avatar answered Sep 25 '22 04:09

TheCodingFrog


The Problem: Github api response doesn't contain all the relevant data.

Solution: The api from server is limiting the amount of items the user gets and splitting it into pages (pagination). You should explicitly Specify in your request how many items you'd like to receive from server pagination engine ,using formula for Github pagination api

?page=1&per_page=<numberOfItemsYouSpecify>" 

For example: I'd like to get all my collaborators info in my private repo. I'm performing curl request to Github contains: username, authentication token , Organization and repository name and api call with pagination magic.

curl -u johnDoe:abc123$%^ https://api.github.com/repos/MyOrganizationName/MyAwesomeRepo/collaborators?page=1&per_page=1000" 

Explanation:

What is Pagination: Pagination is the process of splitting the contents or a section of a website into discrete pages. Users tend to get lost when there's bunch of data and with pagination splitting they can concentrate on a particular amount of content. Hierarchy and paginated structure improve the readability score of the content. Loading pages is due to the less content on each item and each page has a separate URL which is easy to refer.

In this use case Github api splits the result into 30 items per resonse, depends on the request

Github reference:

Different API calls respond with different defaults. For example, a call to List public repositories provides paginated items in sets of 30, whereas a call to the GitHub Search API provides items in sets of 100

like image 26
avivamg Avatar answered Sep 26 '22 04:09

avivamg