dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
5.93k stars 1.14k forks source link

Get all followers of a channel using followersFeed.items$.subscribe() #1750

Open gltched-usr opened 8 months ago

gltched-usr commented 8 months ago

Form

Put an [x] if you meet the condition, else leave [ ].

Question

I want to get all followers of a channel, the code below only works for small channels with up to 500 followers. Can someone help me to make it work for more followers?

Code

async function getFollowers(channel) {
    await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);

    const id = await ig.user.getIdByUsername(channel);
    const followersFeed = await ig.feed.accountFollowers(id);
    return new Promise((resolve, reject) => {
        let channels = [];

        followersFeed.items$.subscribe(
            followers => {
                channels = channels.concat(...followers.map(item => item.username));
            },
            error => {
                console.error("Error:", error);
                if (channels.length < 0) {
                    reject(error, channels);
                }
                else {
                    resolve(channels, true);
                }
            },
            () => {
                resolve(channels, false);
            }
        );
    });
};

Error and Output

Error: IgResponseError: GET /api/v1/friendships/47451104466/followers/?max_id=1050%7CQVFCZmtPME0zZW9IY3RyWFdGVVE4VTJQd3VJMm5YcF9UZi0wX0NiZ1FpeWhqSlJJQ1VoaVd4bW5OR1FDWnlkRHk5eHg1ak5EX0dOOE0zMVRjRXJ0WmotZg%3D%3D&order=default&query=&enable_groups=true - 401 Unauthorized; Please wait a few minutes before you try again.
igornazarov1991 commented 5 months ago

@ColorsCrypt , I have the same issue. It obviously happens due to rate limits. However, web version of Instagram is capable of loading as many followers as needed. Are you able to solve it?