b31ngd3v / MyIGBot

MyIGBot is a Private API for Instagram to like, follow, comment, view & intaract with stories, upload post & stories, get all information about a user/posts and get posts based on locations/hashtags. It also supports proxy.
https://pypi.org/project/myigbot/
MIT License
174 stars 35 forks source link

Discussion about Instagram Rate limits (using story_view function) #17

Open null-routed opened 3 years ago

null-routed commented 3 years ago

First of all, thanks @b31ngD3v for building this API. I recently built a quick script to view accounts' stories in loop. Here's the code

from myigbot import MyIGBot
import time
import random

bot = MyIGBot(username,pw)

storiesCount = 0

def getLastMediaLikers(account):

    # Try to get a list of users that liked the account's last post. If the account has no posts or it's private, return []

    try:
        getMedias = bot.user_posts(account)
        if getMedias == []: return []

        getLikers = bot.post_likers(getMedias[0])
        print(f"Got {len(getLikers)} media likers for the account {account}")
        return getLikers
    except:
        return [] # If anything goes wrong, return an empty list

def storyView(account):
    global storiesCount

    # Attempt to view the story of the account. If successful, increment storiesCount

    try:
        print("Attempting story view for",account)
        if bot.story_view(account) == 200: storiesCount += 1
        print(f"Current stories count: {storiesCount}")
        time.sleep(2.5)
    except:
        pass # In case something goes wrong
    return

currentAccount = input("Please provide an account to start from")
likers = getLastMediaLikers(currentAccount)

while True:

    # View the story of currentAccount and all the one of the first 50 likers of its last post. Then choose a random account and repeat.

    storyView(currentAccount)
    for a in likers:
        storyView(a)
    currentAccount = random.choice(likers)
    likers_sub = getLastMediaLikers(currentAccount)
    while likers_sub == []:
        currentAccount = random.choice(likers)
        likers_sub = getLastMediaLikers(currentAccount)
    likers = likers_sub
    print("Current account:",currentAccount,". Long Sleeping.")
    time.sleep(5)

After a few minutes, my script gets detected and I'm required to change my instagram password due to "a suspiscious login attempt". Does anyone know what IG's rate limits are & what my sleep times should be in order not to run into this?

null-routed commented 3 years ago

Also, since I got this issue this morning, I'm unable to launch my script regardless of my account being fully functional, both on browser and phone. The API manages to log in correctly but it crashes due to

https://www.instagram.com/username/?__a=1

returning

{"message": "feedback_required", "spam": true, "feedback_title": "Try Again Later", "feedback_message": "We limit how often you can do certain things on Instagram to protect our community. Tell us if you think we made a mistake.", "feedback_url": "repute/report_problem/scraping/", "feedback_appeal_label": "Tell us", "feedback_ignore_label": "OK", "feedback_action": "report_problem", "status": "fail"}

However, I'm able to visit this endpoint on browser even after loggin in so it looks like they flagged one of the headers maybe.

EDIT: I'm not sure why but for this specific issue, I had to include "ds_user_id" in the cookies jar. I fixed it by editing line 179 to the following:

self.userId =   login_response.headers['Set-Cookie'].split('ds_user_id=')[1].split(';')[0]              
self.cookie = "sessionid=" + self.sessionid + "; csrftoken=" + self.csrf_token + ";" + 'ds_user_id=' + self.userId + ";"

That cookie is probably not necessary in most cases but apparently it was in mine, so I reckon it wouldn't hurt to edit the code to add it for everyone.

NChechulin commented 3 years ago

@null-routed, Thanks for the feedback! Do you know how many requests you sent? I think this information could be useful to others.

b31ngd3v commented 3 years ago

@null-routed Can you send a pull request, then it'll be easier for me to review? Thanks for opening the issue, have a nice day!!