dilame / instagram-private-api

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

How to get follower count of all followers? #1404

Open ajmeese7 opened 3 years ago

ajmeese7 commented 3 years ago

General Question

When iterating over the items$ in the ig.feed.accountFollowers subscription feed, we have access to the user's PK, username, full name, etc. But if we want more info like the number of followers that user has, we have to make a separate request to ig.user.info with that user's PK.

What I was wondering is if there is a better way to go about getting the follower count of all the followers without pinging that endpoint hundreds of times. Currently my account gets locked out every time I run the code below, because I have enough followers that making that request for every follower far exceeds the API rate limit. Is there some way we can request follower counts in bulk for a list of PK's or something, so I don't have to spam the API to get the information I'm looking for?

Thank you.

Form

Code

const followersFeed = await ig.feed.accountFollowers(userID);
followersFeed.items$.subscribe(
    followers => {
        // Broken into chunks of seemingly random length
        followers.forEach(async (follower) => {
            // TODO: Try to find a way to bypass the repeated calling of this
            // endpoint, as it quickly exhausts all available resources.
            const follower_info = await ig.user.info(follower.pk)
                 .catch(error => handleError('Problem getting follower info', error));
        })
    },
    ..... (other code here)
);

Error and Output

This is what happens after I go over the first few hundred users, I just have this error message pop up hundreds and hundreds of times with different user PK's in the (numbers_here) slot.

(node:30432) UnhandledPromiseRejectionWarning: IgResponseError: GET /api/v1/users/(numbers_here)/info/ - 429 -; Please wait a few minutes before you try again.
    at Request.handleResponseError (C:\Users\username_here\Documents\social-dashboard\node_modules\instagram-private-api\dist\core\request.js:125:16)
    at Request.send (C:\Users\username_here\Documents\social-dashboard\node_modules\instagram-private-api\dist\core\request.js:53:28)
    at async UserRepository.info (C:\Users\username_here\Documents\social-dashboard\node_modules\instagram-private-api\dist\repositories\user.repository.js:9:26)
    at async C:\Users\username_here\Documents\social-dashboard\functions\followers.js:31:27
(node:30432) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
kingbotss commented 3 years ago

That means you are doing it very fast. set timeouts for each account.

ajmeese7 commented 3 years ago

@kingbotss I know that's one possible solution, but I'm looking for something that doesn't take that long. I could easily set a random delay between 1 and 3 seconds for each request, but with thousands of followers it would take an obscene amount of time to iterate over all of them.

vaspoz commented 1 year ago

@ajmeese7 did you find any workable solution for that? I'm also experience the same problem =\

vaspoz commented 1 year ago

@ajmeese7 did you find any workable solution for that? I'm also experience the same problem =\

ajmeese7 commented 1 year ago

Nope, ended up abandoning the project so I no longer have a use case.

vaspoz commented 1 year ago

i found a workaround actually (if anyone still interested) - wrap the call to try/catch and if there's an error (401 usually), just relogin in the catch block.

igornazarov1991 commented 5 months ago

@vaspoz , does your workaround still works for you? I have the same issue. What is interesting is that web version of Instagram is capable of loading as many followers as needed. Of course there are time intervals between the requests made by web. However, I don't see the error mentioned int his ticket at all.

vaspoz commented 4 months ago

Привет @igornazarov1991 nope, it was a one-time script I needed, so it was hacky and dirty. Removed it as soon as it's done the job to not embarrass myself any longer ;)