Code Monkey home page Code Monkey logo

instauto's Introduction

Discord PayPal

instauto is an Instagram automation/bot library (API) written in modern, clean javascript using Google's Puppeteer. Goal is to be very easy to set up, use, and extend, and obey instagram's limits. Heavily inspired by InstaPy, but I thought it was way too heavy and hard to setup.

There is also a GUI application for those who don't want to code: SimpleInstaBot

Setup

  • First install Node.js 8 or newer.

    • On MacOS, it's recommended to use homebrew: brew install node
  • Create a new directory with a file like example.js

  • Adjust your example.js to your needs. If you want to see how it would work without doing any invasive actions, use the dryRun: true option. Toggle headless to see it in action.

  • Open a terminal in the directory

  • Run npm i -g yarn

  • Run yarn add puppeteer instauto

  • Run node example

You can run this code for example once every day using cron or pm2 or similar

See index.js for available options.

Supported functionality

  • Follow the followers of some particular users. (e.g. celebrities.) Parameters like max/min ratio for followers/following can be set.

  • Unfollow users that don't follow us back. Will not unfollow any users that we recently followed.

  • Unfollow auto followed users (also those following us back) after a certain number of days.

  • The code automatically prevents breaching 100 follow/unfollows per hour or 700 per 24hr, to prevent bans. This can be configured.

See example.js for example of features

Tips

  • Run this on a machine with a non-cloud IP to avoid being banned

Troubleshooting

  • If it doesn't work, make sure your instagram language is set to english

Running on Raspberry Pi

Because puppeteer chrome binaries are not provided for RPi, you need to first install chromium using apt.

Then replace your puppeteer launch code:

browser = await puppeteer.launch({
    executablePath: '/usr/bin/chromium-browser',
    headless: true,
    args: ['--disable-features=VizDisplayCompositor'],
});

See also:

Also you might want to install the more lightweight package puppeteer-core instead of puppeteer.

Running with pm2

First install pm2. (npm i -g pm2) Then copy instabot.yml into the same dir as example.js and run:

pm2 start instabot.yml
pm2 save
pm2 startup

Now it will run automatically on reboot! 🙌

Running in Docker

We've added a Docker support for instauto! In the environment section of your docker-compose.yml you need to specify your configuration for login and performance. If you want to raise another container, just copy the service with diff name and run the compose. You'll need to specify different ports.

docker-compose --profile instauto up -d

Donate 🙈

This project is maintained by me alone. The project will always remain free and open source, but if it's useful for you, consider supporting me. :) It will give me extra motivation to improve it.

Paypal | crypto

Credits


Made with ❤️ in 🇳🇴

More apps by mifi.no

Follow me on GitHub, YouTube, IG, Twitter for more awesome content!

instauto's People

Contributors

adrien2p avatar alagos avatar andbas avatar cosme12 avatar dependabot[bot] avatar dlzs8 avatar gherkins avatar joelemanoel avatar lavaswimmer avatar luen avatar maxxxdj avatar mifi avatar muhammed-rajab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

instauto's Issues

Can Desktop app run on raspberry pi?

You say that you need to replace your puppeteer launch code to make the bot work on Raspberry. Can you do that on the Desktop app? Maybe add a option on the app 'running on Raspberry'. Thanks

Library does not handle "Requested" button state

On some profile, after pressing the Follow button, it is not changed to "Following" immediately but changed to "Requested".

In this case the fact the Request was sent is not stored in the cache, but this line throw a log to the console: "Failed to follow user (button did not change state)"

const elementHandle2 = await findFollowUnfollowButton('Following');
      if (!elementHandle2) console.log('Failed to follow user (button did not change state)');

So it makes impossible to unfollow the user in the future, right?

What would be the ideal way to handle this case? (I'm not an instagram expert)

Error

Failed to unfollow, continuing with next Error: Navigate to user returned status 560
����at navigateToUser (/home/pogi/instauto/node_modules/instauto/index.js:182:11)
����at async safelyUnfollowUserList (/home/pogi/instauto/node_modules/instauto/index.js:594:27)
����at async Object.unfollowNonMutualFollowers (/home/pogi/instauto/node_modules/instauto/index.js:657:5)
����at async /home/pogi/instauto/example.js:68:6

Bot visits and keeps revisiting private and excludeUsers resulting in Too Many Requests

The bot could be much more effective if it ignored excludedUsers from search and stopped visiting them repeatedly - as this unnecessary traffic increases the risk of "Too Many Requests".

This could be implemented by:

  1. Storing excludeUsers, incl. private and accounts with wrong follow/following ratio in a json file.
  2. Filtering those users out in the "followUserFollowers"-function.

What do you think about this proposed enhancement?

Failed to follow user followers, continuing Error: Evaluation failed: TypeError: Cannot read property 'user' of undefined

Hello I have got an issue with one of my Instagram account. At the start of the bot I get this error:

Failed to follow user followers, continuing Error: Evaluation failed: TypeError: Cannot read property 'user' of undefined

I think the error is coming from this line

return page.evaluate(() => window._sharedData.entry_data.ProfilePage[0].graphql.user)

Will return

{ ProfilePage: [ {} ] }

instead of

  ProfilePage: [
    {
      logging_page_id: '.................',
      show_suggested_profiles: false,
      show_follow_dialog: false,
      graphql: [Object],
      toast_content_on_load: null
    }
  ]

Do you have any idee how can I fix this ?

Thank's for your amazing work

Don't unfollow active/interactive users

I wonder if it's possible to get a list of accounts that are active/have interacted with you often, and you can have an option to not unfollow them in the "Unfollow auto-followed users" section. i.e. those who have sent you a direct message or replied to a story or liked several posts.

I know there's an "excludeUsers" section you can manually fill it, but if your following grows and you want to auto-unfollow even those who follow you back after a while, but keep certain users who are really interacting with you, it'll be useful if the bot can identify them for you. But I don't know if there's any way to implement that.

User data not found

I'm getting the following error when trying to execute any action on a particular user (e.g. follow their followers):

Failed to follow user followers, continuing Error: Evaluation failed: TypeError: Cannot read property 'user' of undefined
    at __puppeteer_evaluation_script__:1:61

Do you have an idea of what may cause this error and how to fix it?

Hashtag

Would be good to be able to follow by hashtags what do you think ?

Login using Session cookies

I was looking for an API like this, which is still maintained I guess. Great work by the developers. I stumbled upon some ideas to improve this:
1.) if I could be able to install this on a server (a method like this) and let it run for a long period + sending an error notification on email if something went wrong.

2.) (Maybe better approach OR already in use which I'm unaware of) Using session cookies to login (similar to this service) to avoid bot detection.

I'm completely new to node.js but gonna try making the first option work. I will appreciate it if someone could help with this.

Bot not unfollowing

Hi,

For some reason my bot is not unfollowing as it should. Could you help me understandig three things?

  1. Does the bot follows or unfollows first when it start? (SimpleInstaBot unfollows first)
  2. How do I set the variable dontUnfollowUntilTimeElapsed? I don't seem to understand those multiplications
  3. Is there any difference between this and SimpleInstaBot, in terms of the pupeteer implementation?

Add Search Please

Could you please add a feature to search the searchbar?

I will pay

Follow likers of a post

I've added a new method to your tool which instead of usernames, gets an array of post IDs and follows all the users who've liked that post (meaning they actually love that post and had interactions). This seems to be very effective in my experience. Do you mind if I send an MR?

Private Follow Not Working

Hi ! I try to use your bot but it not works with private profile. The bot is not able to find the follow button when the user is private... Do you know why ?
Its weird because the button have the same text value "Follow"

Thanks

Add randomizations to timings

Presumably, instagram already has a signal that detects when interactions with the platform are coming from puppeteer.

It would be advantageous to introduce randomization to timed events. Right now all of these events trigger and the same interval. It would be easy for someone at instagram and observe that the interactions from a given account are interacting with the platform on the same interval over time.

Adding a few degrees of freedom should be enough to trick any easy detection on intervals.

Failed to follow user (button did not change state) Logic

Hi,

I noticed that whenever instauto gets the Failed to follow user (button did not change state) error it continues to:

  1. Like photos of that user which then results to an error, and
  2. The user gets appended to followed.json although it was not successfully followed.

Also, I think it would be more appropriate for the bot to sleep because I think the Failed to follow user (button did not change state) is caused by stricter bot detection logic. Just a suggestion though.

Thanks!
Noname

Input User List

Please put in an option to put user list of usernames to follow unfollow.
I am using simpleinstabot and this function would really help there !

Thank you,

Failed to follow user (button did not change state)

Failed to follow user (button did not change state)

Works on my local linux computer but I get this error on my remote linux server

LOCAL LINUX COMPUTER
Distributor ID: Kali
Description: Kali GNU/Linux Rolling
Release: 2019.4
Codename: kali-rolling

REMOTE LINUX SERVER (GOOGLE CLOUD)
Distributor ID: Debian
Description: Debian GNU/Linux 9.11 (stretch)
Release: 9.11
Codename: stretch

when language switch back to current location after login isLoggedIn func return false even when you are logged in

Hi @mifi looks like when you log in to Instagram sometimes switch back language to the current location and isLoggedIn function return false even when you are logged in because the text "Home" is diff in other languages...

const isLoggedIn = async () => (await page.$x('//*[@aria-label="Home"]')).length === 1;

To pass that checking you need to change the language manually after login at the bottom of the page

Suspicious login attempt

When logging in there starts to pop up a dialog that needs two factor verification by email.
Note that when this process is completed and the session cookies are saved, this message does not appear anymore.
If this becomes a bigger problem then maybe we could implement an IMAP/Gmail mail scanner that automatically goes into the inbox and finds this code.

Screenshot 2019-08-01 at 10 02 42

Unhelpful error message "Follow button not found"

I get this error message occasionally:

Failed to process follower XXXXXXXX Error: Follow button not found
    at followCurrentUser (/home/YYYY/bin/instauto-master/node_modules/instauto/index.js:216:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)

This is for users that I already follow, so it makes sense the follow button isn't found. Probably instauto just shouldn't be visiting them if I already follow them.

Proxy

Hello, is it possible to pass a proxy to the bot?

bug : TypeError: Cannot read property 'click' of undefined

Hello , I execute the scrpit it launches well, enter the nickname and the password then suddenly the window closes.
thanks.

TypeError: Cannot read property 'click' of undefined at module.exports (F:\document\NODE\instauto\node_modules\instauto\index.js:511:23) at processTicksAndRejections (internal/process/task_queues.js:93:5) at async F:\document\NODE\instauto\example.js:51:22 Closing browser

[REQUEST] Follow users who interacted with a photo

Hey guys,

My idea would be that to increase the chances of a profile getting followers back there could be an option to follow the people who interacted with a profile, so it could be done through likes and comments.

An example: Follow all the people who liked and commented on the last post on @facebook

Not loggin in

I tried the OSX Desktopversion, which gives me the following error:

WARNING: Login has not succeeded. This could be because of an incorrect username/password, or a "suspicious login attempt"-message. You need to manually complete the process.

Even though the login has succeeded

instagram bot .py

hey ,
when i try to run my instagram bot , It shows me this error
what should i do ?

File "example.py", line 50, in
'follow', 'follower', 'gain', '.id', 'id', 'bags'],)
File "C:\Users\DAVID-pc\Desktop\instabot.py-38c46365407781e6be745dec83a4781ba0763cdb\src\instabot.py", line 234, in init
self.login()
File "C:\Users\DAVID-pc\Desktop\instabot.py-38c46365407781e6be745dec83a4781ba0763cdb\src\instabot.py", line 309, in login
self.user_id = ui.get_user_id_by_login(self.user_login)
File "C:\Users\DAVID-pc\Desktop\instabot.py-38c46365407781e6be745dec83a4781ba0763cdb\src\userinfo.py", line 41, in get_user_id_by_login
all_data = json.loads(info.text)
File "C:\Users\DAVID-pc\AppData\Local\Programs\Python\Python36\lib\json_init
.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\Users\DAVID-pc\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\DAVID-pc\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Follow following

Thanks for this amazing script, this is a great project and I'm happy this continues to be maintained!
I have a feature suggestion: a good way of growing an account and create real engagement is to follow following users from a user, not followers. Could it be included in a future release?
It looks like it would be a quick method to add to the project but I might not be good enough to create a PR.

Looping script and limits PER

Good day, thank you for this script, I'm not fluent in JavaScript script.
How can I use theMaxfollowperday and maxfollowperhour in index.js.
Also how can I loop example.js. thank you

j

npm install instauto --> not installed
what is my fault?
insta

Error: No node found for selector: a[href="/accounts/login/"]

(Mac Osx Mojave)
Installed the dependencies, added the example.js based on your example, filled out my users, however when I tried to execute I got this error:

Macs-MacBook-Pro:instafollow mysecretuser$ node example.js 
Failed to load cookies
Failed to load followed db
Failed to load unfollowed db
Error: No node found for selector: a[href="/accounts/login/"]
    at assert (/Users/mysecretuser/Work/projects/digitalNomad/instafollow/node_modules/puppeteer/lib/helper.js:270:11)
    at DOMWorld.click (/Users/mysecretuser/Work/projects/digitalNomad/instafollow/node_modules/puppeteer/lib/DOMWorld.js:366:5)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  -- ASYNC --
    at Frame.<anonymous> (/Users/mysecretuser/Work/projects/digitalNomad/instafollow/node_modules/puppeteer/lib/helper.js:111:15)
    at Page.click (/Users/mysecretuser/Work/projects/digitalNomad/instafollow/node_modules/puppeteer/lib/Page.js:1031:29)
    at module.exports (/Users/mysecretuser/Work/projects/digitalNomad/instafollow/node_modules/instauto/index.js:464:16)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Closing browser

Is this the right settings to only unfollow who doesn't follow back?

'use strict';

const puppeteer = require('puppeteer'); // eslint-disable-line import/no-extraneous-dependencies

const Instauto = require('instauto'); // eslint-disable-line import/no-unresolved

const options = {
cookiesPath: './cookies.json',

username: 'test',
password: 'test',

// Global limit that prevents follow or unfollows (total) to exceed this number over a sliding window of one hour:
maxFollowsPerHour: 20,
// Global limit that prevents follow or unfollows (total) to exceed this number over a sliding window of one day:
maxFollowsPerDay: 150,
// (NOTE setting the above parameters too high will cause temp ban/throttle)

maxLikesPerDay: 50,

// Don't follow users that have a followers / following ratio less than this:
followUserRatioMin: 0.2,
// Don't follow users that have a followers / following ratio higher than this:
followUserRatioMax: 4.0,
// Don't follow users who have more followers than this:
followUserMaxFollowers: null,
// Don't follow users who have more people following them than this:
followUserMaxFollowing: null,
// Don't follow users who have less followers than this:
followUserMinFollowers: null,
// Don't follow users who have more people following them than this:
followUserMinFollowing: null,

dontUnfollowUntilTimeElapsed: 0,

// Usernames that we should not touch, e.g. your friends and actual followings
excludeUsers: [],

// If true, will not do any actions (defaults to true)
dryRun: false,
};

(async () => {
let browser;

try {
browser = await puppeteer.launch({ headless: false });

// Create a database where state will be loaded/saved to
const instautoDb = await Instauto.JSONDB({
  // Will store a list of all users that have been followed before, to prevent future re-following.
  followedDbPath: './followed.json',
  // Will store all unfollowed users here
  unfollowedDbPath: './unfollowed.json',
  // Will store all likes here
  likedPhotosDbPath: './liked-photos.json',
});

const instauto = await Instauto(instautoDb, browser, options);

// List of usernames that we should follow the followers of, can be celebrities etc.

// const usersToFollowFollowersOf = [''];

// Now go through each of these and follow a certain amount of their followers

// await instauto.followUsersFollowers({ usersToFollowFollowersOf, skipPrivate: true, enableLikeImages: true });

await instauto.sleep(10 * 60 * 1000);

// This is used to unfollow people - auto-followed AND manually followed -
// who are not following us back, after some time has passed
// (config parameter dontUnfollowUntilTimeElapsed)
await instauto.unfollowNonMutualFollowers();

await instauto.sleep(10 * 60 * 1000);

// Unfollow auto-followed users (regardless of whether they are following us)
// after a certain amount of days

// await instauto.unfollowOldFollowed({ ageInDays: 60 });

console.log('Done running');

await instauto.sleep(30000);

} catch (err) {
console.error(err);
} finally {
console.log('Closing browser');
if (browser) await browser.close();
}
})();

Bot not exited but continues to try

Hi, the bot is awesome and I run it using forever

but I noticed the bot doesn't exit when lost connection to Chromium. For example when macbook goes sleep.

and it constantly writing the same error:

Failed to unfollow, continuing with next Error: Protocol error (Page.navigate): Session closed. Most likely the page has been closed.

It should exit or try to restart chromium

"Session closed" headless Chromium doesn't respond but not exiting

Similar to #19, I get a bunch of:
Failed to follow user followers, continuing Error: Protocol error (Page.navigate): Session closed. Most likely the page has been closed.
from the bot after a while.
It's running headless.
I think it should catch that issue and restart a session or exit so pm2 can take it back up.

undefined is not iterable (cannot read property Symbol(Symbol.iterator))

first of all a big thumbs up to this repository. It has been very helpful in automating our instagram feeds and pages however i'm experiencing this error every time i start the bot.

undefined is not iterable (cannot read property Symbol(Symbol.iterator))
at shuffleArray (/Users/eggseed-Naaman/Desktop/eggseedapp/backend/api/automation-bot/node_modules/instauto/index.js:11:17)
at Object.followUsersFollowers (/Users/eggseed-Naaman/Desktop/eggseedapp/backend/api/automation-bot/node_modules/instauto/index.js:567:44)
at /Users/eggseed-Naaman/Desktop/eggseedapp/backend/api/automation-bot/src/bot.js:52:24

Has anyone faced this problem and if so what can be done to solve it.

i checked the shuffleArray function and it returns the array but for some reason it returns undefined.

followUserFollowers isn't checking limits

Opened issue for #55

Hello, I was using this library and I think I found a small bug: maxFollowsPerHour and maxFollowsPerDay where not being checked.

After digging a little I discovered that the function throttle() was being called only at the begging of the function followUserFollowers() L477. But if you look a little further there is a for L504 where the "user following thing" is done. So I added another call to throttle() at the end of the loop where the condition calls followCurrentUser(follower). That way the max limits are checked every time after a new user is followed.
Hope I was clear.

Like button section not found (Action Blocked on liking images)

Failed to follow user's images solwinkler_ Error: Evaluation failed: Error: Like button section not found
at likeCurrentUserImagesPageCode (puppeteer_evaluation_script:38:27)
at ExecutionContext._evaluateInternal (/opt/bitnami/projects/instauto/node_modules/puppeteer/lib/cjs/puppeteer/common/Execut
ionContext.js:217:19)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async ExecutionContext.evaluate (/opt/bitnami/projects/instauto/node_modules/puppeteer/lib/cjs/puppeteer/common/Execution
Context.js:106:16)
at async likeCurrentUserImages (/opt/bitnami/projects/instauto/node_modules/instauto/index.js:439:5)
at async followUserFollowers (/opt/bitnami/projects/instauto/node_modules/instauto/index.js:509:15)
at async Object.followUsersFollowers (/opt/bitnami/projects/instauto/node_modules/instauto/index.js:538:9)
at async /opt/bitnami/projects/instauto/example.js:65:5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.