GitHub Api: Custom Subscribers - Paging?

I play with some Javascript and Github APIs and I came up with one problem.

Every time I try to call the followers of any user who has followers, the callback I receive from the server shows only 30 users. For instance:

https://api.github.com/users/vojtajina/followers - 30 followers

and user subscribers from the original website:

https://github.com/vojtajina/followers - 1,039 subscribers

My questions is what is happening? There is no โ€œnext page" in the callback from the server. How can I get all my subscribers in a callback?

+5
source share
1 answer

The maximum number of elements per page is 100, so using the per_page=100 querystring parameter, the result will be increased by 100 users per page:

 https://api.github.com/users/vojtajina/followers?per_page=100 

Using the page querystring parameter, you can control pagination. For example, to get a second page, you would add page=2 :

 https://api.github.com/users/vojtajina/followers?per_page=100&page=2 

If you want to get all the followers, you have to iterate over the pages until you get an empty array.


If you want to use this in a Node.js / JavaScript application (on client), you can use gh.js - the library I created that handles this:

 var GitHub = require("gh.js"); var gh = new GitHub({ token: "an optional token" }); gh.get("users/vojtajina/followers", { all: true } function (err, followers) { console.log(err || followers); // do something with the followers }); 
+4
source

Source: https://habr.com/ru/post/1232909/


All Articles