Skip to content

Instantly share code, notes, and snippets.

@kanelv
Last active July 1, 2024 06:33
Show Gist options
  • Save kanelv/50f82d0d1e49338d6af0bdbac0d8ff2b to your computer and use it in GitHub Desktop.
Save kanelv/50f82d0d1e49338d6af0bdbac0d8ff2b to your computer and use it in GitHub Desktop.
Script for Filtering: Followers, Followings, Don't Follow Me Back, I Don't Follow Back on Instagram

Script for Filtering: Followers, Followings, Don't Follow Me Back, I Don't Follow Back on Instagram

How to Use:

Step 1:

  • Log in to your Instagram account using a browser such as Chrome. (The script is verified to work correctly on Chrome.)

Step 2:

  • Open the Developer Tools in Chrome. You can do this by:
    • Pressing F12 on your keyboard, OR
    • Right-clicking anywhere on your browser window, selecting "Inspect", and then switching to the "Console" tab.

Note: You can type clear() in the console and press Enter to clear the console window.

Step 3,

  • Copy and paste the code from the instagram-follow-filter.js file into the console.
  • Replace username at line number 1 with your Instagram username.

Note:

  • The script not only helps you filter followers on your Instagram account but also allows you to filter followers from any other account by replacing username with the account's username at line number 1.
  • As of now, the script has limitations when filtering all types of follows from an account that has a total follower count, including all types of follows, under 100k. We are actively working to enhance its functionality in future updates.
const username = "somebody_username";
/**
* Initialized like this so we can still run it from browsers, but also use typescript on a code editor for intellisense.
*/
let followers = [{ username: "", full_name: "" }];
let followings = [{ username: "", full_name: "" }];
let dontFollowMeBack = [{ username: "", full_name: "" }];
let iDontFollowBack = [{ username: "", full_name: "" }];
followers = [];
followings = [];
dontFollowMeBack = [];
iDontFollowBack = [];
(async () => {
try {
console.log(`Process started! Give it a couple of seconds`);
const userQueryRes = await fetch(
`https://www.instagram.com/web/search/topsearch/?query=${username}`
);
const userQueryJson = await userQueryRes.json();
console.log("userQueryJson", userQueryJson);
const userId = userQueryJson.users.map(u => u.user)
.filter(
u => u.username === username
)[0].pk;
console.log("userId", userId);
let after = null;
let has_next = true;
while (has_next) {
await fetch(
`https://www.instagram.com/graphql/query/?query_hash=c76146de99bb02f6415203be841dd25a&variables=` +
encodeURIComponent(
JSON.stringify({
id: userId,
include_reel: true,
fetch_mutual: true,
first: 50,
after: after,
})
)
)
.then((res) => res.json())
.then((res) => {
console.log("res", res)
has_next = res.data.user.edge_followed_by.page_info.has_next_page;
after = res.data.user.edge_followed_by.page_info.end_cursor;
followers = followers.concat(
res.data.user.edge_followed_by.edges.map(({ node }) => {
return {
username: node.username,
full_name: node.full_name,
};
})
);
});
}
console.log({ followers });
after = null;
has_next = true;
while (has_next) {
await fetch(
`https://www.instagram.com/graphql/query/?query_hash=d04b0a864b4b54837c0d870b0e77e076&variables=` +
encodeURIComponent(
JSON.stringify({
id: userId,
include_reel: true,
fetch_mutual: true,
first: 50,
after: after,
})
)
)
.then((res) => res.json())
.then((res) => {
has_next = res.data.user.edge_follow.page_info.has_next_page;
after = res.data.user.edge_follow.page_info.end_cursor;
followings = followings.concat(
res.data.user.edge_follow.edges.map(({ node }) => {
return {
username: node.username,
full_name: node.full_name,
};
})
);
});
}
console.log({ followings });
dontFollowMeBack = followings.filter((following) => {
return !followers.find(
(follower) => follower.username === following.username
);
});
console.log({ dontFollowMeBack });
iDontFollowBack = followers.filter((follower) => {
return !followings.find(
(following) => following.username === follower.username
);
});
console.log({ iDontFollowBack });
console.log(
`Process is done: Type 'copy(followers)' or 'copy(followings)' or 'copy(dontFollowMeBack)' or 'copy(iDontFollowBack)' in the console and paste it into a text editor to take a look at it'`
);
} catch (err) {
console.log({ err });
}
})();

Disclaimer

The script and instructions provided here are intended for educational and informational purposes only. By using the script and following the instructions, you acknowledge and agree that:

  1. No Guarantees: There is no guarantee that the script will function error-free or that it will achieve specific results on your Instagram account or any other account.

  2. Use at Your Own Risk: You use the script at your own risk. The developers and contributors of the script are not responsible for any damage, loss of data, or other consequences that may occur from using the script.

  3. Account Security: It is your responsibility to ensure the security of your Instagram account and any accounts you interact with using the script. Be cautious when using third-party scripts and always verify the source and functionality before implementation.

  4. Legal Compliance: Ensure that your use of the script complies with Instagram's terms of service and any applicable laws and regulations.

  5. Modifications: You may modify the script for personal use, but redistribution or commercial use without permission from the original authors is prohibited.

  6. Community Contribution: This script is a community contribution (open source). The author(s) do not assume any responsibility if the script is used for any negative activities or consequences.

By using the script and following these instructions, you agree to the terms outlined above. If you do not agree with these terms, refrain from using the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment