Skip to content

Instantly share code, notes, and snippets.

@sydneyitguy
Created January 22, 2020 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sydneyitguy/bfab4f322ba93814c9526cbfdb155dd7 to your computer and use it in GitHub Desktop.
Save sydneyitguy/bfab4f322ba93814c9526cbfdb155dd7 to your computer and use it in GitHub Desktop.
Get Instagram Followers
const random_wait_time = (waitTime = 300) => new Promise((resolve, reject) => {
setTimeout(() => {
return resolve();
}, Math.random() * waitTime);
});
const get_followers = async(userId, userFollowerCount) => {
let userFollowers = [],
batchCount = 20,
actuallyFetched = 20,
url = `https://www.instagram.com/graphql/query/?query_hash=c76146de99bb02f6415203be841dd25a&variables={"id":"${userId}","include_reel":true,"fetch_mutual":true,"first":"${batchCount}"}`;
while (userFollowerCount > 0) {
const followersResponse = await fetch(url)
.then(res => res.json())
.then(res => {
const nodeIds = [];
for (const node of res.data.user.edge_followed_by.edges) {
nodeIds.push(node.node.id);
}
actuallyFetched = nodeIds.length;
return {
edges: nodeIds,
endCursor: res.data.user.edge_followed_by.page_info.end_cursor
};
}).catch(err => {
userFollowerCount = -1;
return {
edges: []
};
});
await random_wait_time();
userFollowers = [...userFollowers, ...followersResponse.edges];
userFollowerCount -= actuallyFetched;
url = `https://www.instagram.com/graphql/query/?query_hash=c76146de99bb02f6415203be841dd25a&variables={"id":"${userId}","include_reel":true,"fetch_mutual":true,"first":${batchCount},"after":"${followersResponse.endCursor}"}`;
}
console.log(userFollowers);
return userFollowers;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment