InstaPy icon indicating copy to clipboard operation
InstaPy copied to clipboard

Note to developers

Open redsector72 opened this issue 7 years ago • 26 comments

Here is my finding, to present moment: They are not checking if is a bot or not, they are simply enforcing multiple simultaneous login. If you are running the official app WHILE anything else is browsing instagram, human or bot, they ban all and future actions, except the ones coming from their app.

That's probably why some people have problems and some not. The one who are real people, have trouble, the one that are only bot, works fine.

redsector72 avatar Aug 01 '19 14:08 redsector72

Uhh, interesting, how many instances you have noticed this pattern ?

CharlesCCC avatar Aug 01 '19 14:08 CharlesCCC

It's easy to reproduce. The instant you open the app, the browser version get ignored in the actions. If the browser continue the action, they ban it. Even if you are human. I've noticed it because I have opened a direct message while i was looking at the bot doing. The last picture liked was the one previous to the app launch.

redsector72 avatar Aug 01 '19 15:08 redsector72

@redsector72 Do you know how long the block will lift when you weren't using the mobile App ?

CharlesCCC avatar Aug 01 '19 16:08 CharlesCCC

I can confirm the same behavior on my end. Seems that the block is active for the duration of the session as I’m able to run my script as soon as I remove the cookie file.

Frituurpanda avatar Aug 01 '19 19:08 Frituurpanda

@Frituurpanda Are you saying, after you used mobile app, you will have to delete existing cookie from the log folder and re-generate it in order to run it without block ?

CharlesCCC avatar Aug 01 '19 20:08 CharlesCCC

It's easy to reproduce. The instant you open the app, the browser version get ignored in the actions. If the browser continue the action, they ban it. Even if you are human. I've noticed it because I have opened a direct message while i was looking at the bot doing. The last picture liked was the one previous to the app launch.

I have 5 accounts running InstaPy, 3 of them are of people that use the app all the time, in this cases I get banned and can't do any automatizations at all. The other 2 accounts, are just bots and works perfectly fine.

First I was thinking it was a detection of geolocation (all accounts are from argentina) and InstaPy was runnining from DigitalOcean Servers (Germany, EEUU, etc.) but I discard this when try InstaPy with a vps from Argentina and get banned too.

jctommasi avatar Aug 01 '19 20:08 jctommasi

@jctommasi thank you for sharing this insight.

Now the 5 million dollar questions is how can we get over this detection block...

CharlesCCC avatar Aug 01 '19 20:08 CharlesCCC

Going to check this with my account overnight. If you are right, shutting down the app, then clearing cookie and having a good long Instapy session should not trigger a block...

Tachenz avatar Aug 01 '19 22:08 Tachenz

@jctommasi thank you for sharing this insight.

Now the 5 million dollar questions is how can we get over this detection block...

Some users said in others topic: simulating mobile.. A solution just for now is being concious when open instagram app, but that is unsustainable, an interesting feature may be an api through telegram bot where you can close sessions by an "/stop" command before open IG app or best: developing an simple mobile app who detects when you open ig app and it check through an api if is a session running, if it is, alert the user:

Session is running: opt1:stop session and open instagram app. opt2:get out of here and let the bot make his job

i'm just brainstorming XD

jctommasi avatar Aug 02 '19 01:08 jctommasi

Guys, I don't want to disturb your observations but I am experiencing quite the opposite since few days: I have two accounts running Instapy, I use the official mobile app simultaneously with one of them and it works perfectly fine for this one (Instapy and app) but the other one that only runs Instapy got blocked on Instapy for any action. Can't follow, like or unfollow. But not blocked on the app...

papillon-unix avatar Aug 02 '19 09:08 papillon-unix

Yeah, it was a nice theory but it does not work : Logged off my Instagram app, cleared cookies Instapty banned within 5 follows at a speed of 1 follow per 10 minutes.

Tachenz avatar Aug 02 '19 10:08 Tachenz

This is my script running with a test account (I developed some functions to randomize everything), I never add it to the IG app, last post was 23/12/2018 and I'm running InstaPy perfectly with chrome

#credentials
insta_username = 'username'
insta_password = 'password'

#telegram notif
telegram_chat = '-1111111'
bot_token = 'tokenbot'

# set security random countdown
countdown_to_start = random.randint(0,3600)
countdown = str(int(countdown_to_start/60))

session_id =  str(countdown_to_start)
path = sys.path[0] + '/'

#CHECK IF ACCOUNT HAS BANS
#A PHP SCRIPT RUNS EVERY 10 MINUTES, AND CHECK GENERAL.LOG IF ACC HAS WARNINGS, IF IT IS WRITE "1" in banned.txt
with open(path + 'logs/' + insta_username + '/banned.txt', 'r') as content_file:
    banned_int = int(content_file.read())
    if banned_int:
        requests.get("https://api.telegram.org/bot" + bot_token + "/sendMessage?chat_id=" + telegram_chat + "&text===============\n(id: "+ session_id +") @"+ insta_username + ": account has bans, aborting..\n===============\n".format(datetime.now().strftime("%H:%M:%S")))
        sys.exit(1)

#CHECK IF OTHER SESSION IS RUNNING, until start a session it writes 1 in onsession.txt
#sessions never gets overlayed
with open(path + 'logs/' + insta_username + '/onsession.txt', 'r') as content_file:
    onsession_int = int(content_file.read())
    if onsession_int:
        requests.get("https://api.telegram.org/bot" + bot_token + "/sendMessage?chat_id=" + telegram_chat + "&text===============\n(id: "+ session_id +") @"+ insta_username + ": onsession true, aborting..\n===============\n".format(datetime.now().strftime("%H:%M:%S")))
        sys.exit(1)

#set workspace
set_workspace("/InstaPy")

#random sleep to randomize start times (this script runs every 45 minutes from cron)
time.sleep(countdown_to_start)

#CHECK AGAIN IF OTHER SESSION IS RUNNING and write 1 onsession.txt
with open(path + 'logs/' + insta_username + '/onsession.txt', 'r') as content_file:
    onsession_int = int(content_file.read())
    if onsession_int:
        requests.get("https://api.telegram.org/bot" + bot_token + "/sendMessage?chat_id=" + telegram_chat + "&text===============\n(id: "+ session_id +") @"+ insta_username + ": onsession true, aborting..\n===============\n".format(datetime.now().strftime("%H:%M:%S")))
        sys.exit(1)
    else:
        with open(path + 'logs/' + insta_username + '/onsession.txt', 'w') as content_file:
            content_file.write(str(1))
            requests.get("https://api.telegram.org/bot" + bot_token + "/sendMessage?chat_id=" + telegram_chat + "&text===============\n(id: "+ session_id +") @"+ insta_username + ": onsession false, starting in " + countdown +"m\n===============\n".format(datetime.now().strftime("%H:%M:%S")))

def get_session():
    session = InstaPy(username=insta_username,
                      password=insta_password,
                      headless_browser=False,
                      bypass_with_mobile=True,
		      nogui=True,
                      disable_image_load=False,
                      multi_logs=True)

    return session


def follow():

    sleep_time = random.randint(120,240)
    num_retries = 2

    for x in range(0, num_retries):  # try 2 times

        try:
            # get a session!
            session = get_session()
            # let's go!
            with smart_run(session):

                session.set_relationship_bounds(enabled=True,
                            potency_ratio=-0.70,
                            # potency_ratio=None,
                            delimit_by_numbers=True,
                            max_followers=6000,
                            max_following=3000,
                            min_followers=30,
                            min_following=30)

                session.set_skip_users(skip_private=True,
                                   skip_no_profile_pic=True,
                                   skip_business=False,
                                   business_percentage=100)

                session.set_quota_supervisor(enabled=True,
                sleep_after=['likes_h', 'comments_d', 'follows_h', 'unfollows_h', 'server_calls_d'], sleepyhead=True, stochastic_flow=True, notify_me=True,
                                          peak_likes=(10, None),
                                           peak_comments=(1, 1),
                                            peak_follows=(20, None),
                                             peak_unfollows=(15, None),
                                              peak_server_calls=(None, 4700))

                #DATABASE
                hitting_accounts = ['discovery', 'natgeowild', 'bbcearth', 'animalplanet','natgeoadventure', 'natgeoadventure','discoverychannelin', 'natgeochannel', 'discovery.hd', 'nasa', 'history', 'animalplanetindia', 'natgeoexpeditions', 'natgeo.la', 'natgeoindia', 'oceana', 'sciencechannel', 'time', 'insidenatgeo']

                hitting_tags = ['landscapephotography', 'landscapelovers', 'landscape_captures', 'landscapes', 'hiking', 'trees', 'mountain', 'sunrise', 'scenery', 'skyporn', 'outdoors', 'cloudporn', 'instanature', 'tree', 'water', 'forest', 'naturelover', 'panorama', 'autumn', 'skylovers', 'love', 'instagood', 'photooftheday', 'fashion', 'beautiful', 'happy', 'cute', 'tbt', 'like4like', 'followme', 'picoftheday', 'follow', 'me', 'selfie', 'summer', 'art', 'instadaily', 'friends', 'repost', 'nature', 'girls', 'fun', 'style', 'smile', 'food', 'instalike', 'family']


                # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

                #RANDOMIZING ACC, TAG, AND FOLLOW NUMBERS
                rand_acc_numbers = random.randint(1,3)
                rand_tag_numbers = random.randint(1,2)
                rand_photos = random.randint(1,2)

                remove_follow_requests = random.randint(1,5)
                rand_unfollow = random.randint(1,2)
                rand_follow = random.randint(5,8)
                rand_like = random.randint(1,3)
                rand_storyview = random.randint(1,100)

                rand_like_str = str(rand_like)
                rand_follow_str = str(rand_follow)
                rand_unfollow_str = str(rand_unfollow)

                #DISORDERING
                random.shuffle(hitting_tags)
                random.shuffle(hitting_accounts)

                #CUTTING
                hitting_accounts = hitting_accounts[:rand_acc_numbers]
                hitting_tags = hitting_tags[:rand_tag_numbers]

                #just in case of debug i'm converting the selected tags in string to be able send this through telegram, also list_amout is an estimated number of procesed accounts
                hitting_tags_str = ' '.join(str(e) for e in hitting_tags)
                hitting_accounts_str = ' '.join(str(e) for e in hitting_accounts)
                list_amount = str(rand_follow*len(hitting_accounts))

                session.set_user_interact(amount=1, randomize=True, percentage=20, media='Photo')
                session.set_do_like(enabled=True, percentage=100)
                session.set_do_comment(enabled=False, percentage=0)
                session.set_do_follow(enabled=False, percentage=0)
                session.set_do_story(enabled = True, percentage = rand_storyview, simulate = False)
                session.set_action_delays(enabled=True,like=1,follow=1,unfollow=1,story=1,randomize=True, random_range=(120, 340))

                def like_feed():
                    session.like_by_feed(amount=rand_like, randomize=True, unfollow=True, interact=True)

                def like_tags():
                    session.like_by_tags(hitting_tags, amount=rand_like)

                def follow_tags():
                    session.follow_by_tags(hitting_tags, amount=rand_follow)

                def follow_followers():
                    session.follow_user_followers(hitting_accounts, amount=rand_follow, randomize=True, interact=True)

                def follow_likers():
                    session.follow_likers(hitting_accounts, photos_grab_amount = rand_photos, follow_likers_per_photo = rand_follow, randomize=True, interact=True)

                def unfollow_remove():
                    session.unfollow_users(amount=rand_unfollow, InstapyFollowed=(True, "all"), style="FIFO", unfollow_after=90*60*60, sleep_delay=600)
                    session.remove_follow_requests(amount=remove_follow_requests, sleep_delay=600)

                func_list = [follow_likers, unfollow_remove, like_tags, follow_followers, like_feed, follow_tags]

                requests.get("https://api.telegram.org/bot" + bot_token + "/sendMessage?chat_id=" + telegram_chat + "&text===============\n(id: "+ session_id +") @"+ insta_username + ": session launched succesfully\n===============\n".format(datetime.now().strftime("%H:%M:%S")))

                while func_list:
                    choice = rchoice(func_list)
                    choice();
                    func_list.remove(choice)

                str_error = None

        except Exception as str_error:
            pass

            if str_error:
                requests.get("https://api.telegram.org/bot" + bot_token + "/sendMessage?chat_id=" + telegram_chat + "&text===============\n(id: "+ session_id +") @"+ insta_username + ": ERROR, traceback detected\n===============\n".format(datetime.now().strftime("%H:%M:%S")))
                time.sleep(sleep_time)  # wait before trying to fetch the data again

        else:
            break

follow()

#onsession=0
with open(path + 'logs/' + insta_username + '/onsession.txt', 'w') as content_file:
    content_file.write(str(0))

requests.get("https://api.telegram.org/bot" + bot_token + "/sendMessage?chat_id=" + telegram_chat + "&text===============\n(id: "+ session_id +") @"+ insta_username + ": session has came to end\n===============\n".format(datetime.now().strftime("%H:%M:%S")))

Some notes: session tasks are stored in functions to be able randomize the order of execution in every session everything is inside a try in case of an error in connection is raised. try is inside a for, in case of error, it loop again

jctommasi avatar Aug 02 '19 16:08 jctommasi

@Frituurpanda Are you saying, after you used mobile app, you will have to delete existing cookie from the log folder and re-generate it in order to run it without block ?

Yes. I have the same. It goes well. Until I like 1 picture in the mobile app Basically you have to log out on the phone until the session is done. That helps for my account.

Tr1pke avatar Aug 03 '19 17:08 Tr1pke

guys I got one really important question.

if you are on instagram with you normal Webbrowser and like a picture or do a comment and then you like a picture on your app and go back to the normal Webbrowser and do another like. is this blocked or not ? because if this is NOT blocked then we just have to focus on hiding selenium even more :) and if so ... instagram is fucking crazy :D

breuerfelix avatar Aug 03 '19 20:08 breuerfelix

@breuerfelix no, when I do what you said I don't get blocked. It's crazy, I can't really explain the problem because I have the exact same use of two accounts (Normal browser, app, and Instapy) and one got blocked on Instapy but works perfectly on App and browser, and the second one not blocked at all...

papillon-unix avatar Aug 03 '19 21:08 papillon-unix

The moment I like one picture on the app while my bot is on my bot is blocked and I have to remove cookie and start it again every time I like a photo. Didn’t try it with following and unfollowing

Tr1pke avatar Aug 03 '19 22:08 Tr1pke

@Tr1pke so I am not talking about the bot I am talking about a regular browser :) please try this.

@papillon-unix thanks for testing that ! this means that instagram is detecting it in another way ... do you have the bot running on the current dev branch ( with the hide headless firefox extension) ?

if so, we need to improve it way more !

breuerfelix avatar Aug 04 '19 10:08 breuerfelix

Yeah it seems I have this problem too (although I hadn't noticed before!) so thanks for bringing it to my attention :) Look forward to seeing if there is another solution except for simply not running at the same time!

lezlea avatar Aug 05 '19 22:08 lezlea

@Tr1pke so I am not talking about the bot I am talking about a regular browser :) please try this.

@papillon-unix thanks for testing that ! this means that instagram is detecting it in another way ... do you have the bot running on the current dev branch ( with the hide headless firefox extension) ?

if so, we need to improve it way more !

For me as you said I can interact in my home web browser fine and not get a block. But I get a block on my linux/proxy bot Chrome browser.

I'm going to try using my local residential IP as a proxy and see if that makes a difference.

lezlea avatar Aug 06 '19 08:08 lezlea

Yesterday I realized on my side that before doing any action, they're detecting Selenium/Webdriver somehow. I did compare the instances of a running browser without Selenium, and a running browser with Selenium.

The browser with Selenium is never able to load more than 12 profiles from my "Following" list, it doesn't load more profiles when scrolling, and I'm able to do that without Selenium.

I did compare the browser, and everything looks similar (the extension we're using is doing that), but there is something missing that we still don't know what it's.

converge avatar Aug 06 '19 11:08 converge