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

How to Get a huge number of followers using getFollowers function without reaching the Server request Limit #226

Open
khanakhun opened this issue Feb 7, 2021 · 1 comment

Comments

@khanakhun
Copy link

const Instagram = require("instagram-web-api");
require('dotenv').config();
const FileCookieStore = require('tough-cookie-filestore2')

const cookieStore = new FileCookieStore('./cookies.json')

const { username, password } = process.env;

const client = new Instagram({ username, password , cookieStore });

client.login();

// to getting userId by Username
const getUserId = async (username) =>{
let userId;
await client.getUserByUsername({username: username}).then( user => {
userId = user.id;
});
return userId;
}

// getting User FollowersofUser
const getFollowersCount = async (username) => {
let count;
let userName;
await client.getUserByUsername({ username:username }).then(user =>{
userName = user.id;
})

await client.getFollowers({ userId: userName, first: 20, after: end_cursor }).then(followers => {
count = followers.count
})
return count;
}

// Timer
const sleep = (ms) => {
return new Promise( resolve => setTimeout(resolve, ms))
};

let followersofUser = [];

// Get Followers Data
const getFollowersData = async (userName) => {

let UserToFind = await getUserId(userName);
let count = await getFollowersCount(userName);
let end_cursor;

while(followersofUser.length <= count){
await client.getFollowers({ userId : UserToFind , first: 20 , after : end_cursor }).then(followers => {
followers.data.forEach(function(value){
followersOfUser.push(value);
});
end_cursor = followers.page_info.end_cursor;
sleep(4000)
})

}

return followersofUser;
};

let followersData = getFollowersData('mira.ibiza');
console.log(followersData);

module.exports = {
getFollowersData
}

@MonsieurBibo
Copy link

Hey, as said in many previous issues, Instagram does have some rate limits for their Web API. It seems to be 200 requests/hour.

1 request every 4000 ms equals 900 requests an hour, you need to slow down your requests.

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