Created
January 22, 2020 09:45
-
-
Save sydneyitguy/bfab4f322ba93814c9526cbfdb155dd7 to your computer and use it in GitHub Desktop.
Get Instagram Followers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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