Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Api: User followers - paging?

I am playing with some Javascript and Github API, and I've came to one problem.

Each time, when I try to call for followers of any user who has followers, the callback that I get from the server shows only 30 users. For example:

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

and user followers from original website:

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

My questions is - what is going on? There is no 'next page' in the callback from the server. How can I get all of his/hers followers in the callback?

like image 866
uksz Avatar asked Oct 04 '15 15:10

uksz


People also ask

How do I see my followers on GitHub?

Viewing followers on GitHubClick a user image to display that user's profile. Click followers under their profile image.

What is API GitHub Com users?

The Users API allows to get public and private information about the authenticated user. Users. Get the authenticated user. Update the authenticated user. List users.

How do I find users on GitHub?

Create an async function getUsers(names) , that gets an array of GitHub logins, fetches the users from GitHub and returns an array of GitHub users. The GitHub url with user information for the given USERNAME is: https://api.github.com/users/USERNAME . There's a test example in the sandbox.


1 Answers

The max number of items per page is 100, so using the per_page=100 querystring parameter will increase the result to have 100 users per page:

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

Using the page querystring parameter, you have control to pagination. For example, to get the second page, you should 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 the pages until you receive an empty array.


If you want to use this into a Node.js / JavaScript (on client) app, you can use gh.js–a library I developed which 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
});
like image 117
Ionică Bizău Avatar answered Nov 15 '22 09:11

Ionică Bizău