Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why getFollowers print only the first 50 results? #256

Open
alexduca opened this issue May 28, 2021 · 1 comment
Open

Why getFollowers print only the first 50 results? #256

alexduca opened this issue May 28, 2021 · 1 comment

Comments

@alexduca
Copy link

alexduca commented May 28, 2021

I want get all my followers list but i get only the first 50 results... after that i get this error

(node:8088) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'username' of undefined
at C:\Users\ducaa\Desktop\pupp\test.js:32:51
at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:94:32)
(node:8088) TypeError: Cannot read property 'username' of undefined
at C:\Users\ducaa\Desktop\pupp\test.js:32:51
(node:8088) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:94:32)


THIS IS THE CODE

const userprompt = await prompts(questions);
var username = userprompt['username'];
var password = userprompt['password'];

const client = new Instagram({ username, password });
await client.login();

const delay = ms => new Promise(resolve => setTimeout(resolve, ms))

const userdata = await client.getUserByUsername({ username: client.credentials.username });
var myuserid = userdata['id'];
var myfollowerscount = userdata['edge_followed_by']['count'];

console.log('Count My Followers : '+myfollowerscount);

const myfollowers = await client.getFollowers({ userId: myuserid, first: myfollowerscount });  


var numb = 0;
while(numb < myfollowerscount){
    console.log(numb+1, myfollowers.data[numb]['username']);
    if(numb > 35){
        await delay(4000);
    }
    numb++;
}
console.log('secondpart');
@XeraFiu-YTB
Copy link

XeraFiu-YTB commented Jun 6, 2021

Hey,
You have a variable has_next_page that inform you if you can change your page to end_cursor (next page of follower).
The first parameters is limited to 50, it's the number of followers per pages.

Here it is a sinple code to list all your followers :

(async () => {
    //List of all Followers Name
    let myFollowers = []

    let myId = "myUserId"

    let followers = await client.getFollowers({ userId: myId })
    //get your followers on the first page
    let nextPage = followers.page_info.has_next_page
    //true if you have an other page of followers
    let cursor = followers.page_info.end_cursor
    //next page of follower
    addFollowersName(followers.data)

    //loop to navigate into all the pages of followers
    while(nextPage) {
        followers = await client.getFollowers({ userId: id, first: 50, after: cursor})
        nextPage = followers.page_info.has_next_page
        cursor = followers.page_info.end_cursor
        addFollowersName(followers.data)
    }

    console.log(`List of all my Followers : ${myFollowers.join("\n- ")}`)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants