question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unfollow Users who aren't following you.

See original GitHub issue

General Question

Form

Put an [x] if you meet the condition, else leave [ ].

Question

Hello, i have wrote a little code to unfollow users who aren’t following you. Can you please take a look at it, and maybe add it as a template or you can critique and improve it.

Code

A meaningful section of your code (else delete this). If you are using TypeScript replace js with typescript.

const { IgApiClient } = require('instagram-private-api');

const ig = new IgApiClient();

ig.state.generateDevice(process.env.USERNAME);

(async () => {
    await ig.simulate.preLoginFlow();
    /*
     Logging in to account
     */
    const auth = await ig.account.login(process.env.USERNAME, process.env.PASSWORD);
    const followersFeed = ig.feed.accountFollowers(auth.pk);
    const followingFeed = ig.feed.accountFollowing(auth.pk);
    const followers = [
        ...await followersFeed.items(),
        ...await followersFeed.items(),
    ]
    const following = [
        ...await followingFeed.items(),
        ...await followingFeed.items(),
    ]
   /*
     Making a new set of all user usernames 
     */
    const users = new Set(followers.map(({ username }) => username));
    /*
     Filtering the ones who aren't following you back
     */ 
    const notFollowingYou = following.filter(({ username }) => !users.has(username));
    /*
     Loop through eash and unfollowing them.
     (suggested change by nerix)
     */
    for (const user of notFollowingYou) {
        await ig.friendship.destroy(user.pk);
        console.log(`unfollowed ${user.username}`)
    }
})();

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sellcommented, Jun 11, 2021

Feel free to open a PR.

PR Submitted

1reaction
Nerixyzcommented, Jun 11, 2021

Can you please take a look at it, and maybe add it as a template or you can critique and improve it.

This really depends on the account you’re doing this with.

Just to note: In the inapp followers-page, you can select accounts you don't follow back, however it’s not supported in this library.

const followers = [
    ...await followersFeed.items(),
    ...await followersFeed.items(),
]
const following = [
    ...await followingFeed.items(),
    ...await followingFeed.items(),
]

Don’t do this. This is only possible if you know how many followers the account has. You should use a function. It can be generic over the item of a feed. Here is an example (Comment).

notFollowingYou.forEach((user) => {
    ig.friendship.destroy(user.pk);
    console.log(`unfollowed ${user.username}`)
});

This code works but it will probably break if there are too many users,

  1. Use a for-each loop and await
for (const user of notFollowingYou) {
    await ig.friendship.destroy(user.pk);
    console.log(`unfollowed ${user.username}`)
}
  1. Optionally add a try-catch to handle errors
  2. Optionally add a delay between too many requests
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Find and Unfollow Instagram Users Who Don't Follow ...
Open your profile and navigate to your “Followers” list. · Scroll down the list to check if the user's name in question appears....
Read more >
How to Unfollow Instagram Users Who Don't Follow You Back
The safest way to unfollow people on Instagram is to do it all manually. Yes, that means going through every individual account yourself...
Read more >
How to Unfollow Users on Instagram Who Don't Follow You ...
If you're looking to unfollow Instagram users who don't follow you back, simply navigate to the tab on the app that says, “are...
Read more >
How to unfollow users that don't follow me on Instagram - Quora
You can unfollow people who don't follow you back on Instagram by visiting their profile and clicking on 'Unfollow'. Be very careful when...
Read more >
How to Unfollow Instagram Users Who Don't Follow You Back
Manually Unfollowing Instagram Users · Toggle back to your Google Sheet and paste (CTRL+V or command+V) into the Followers row. Don't worry about ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found