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?
Viewing followers on GitHubClick a user image to display that user's profile. Click followers under their profile image.
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.
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.
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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With