Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
null-routed opened this issue Dec 23, 2020 · 3 comments
Open

Comments

@null-routed
Copy link

null-routed commented Dec 23, 2020

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
Copy link
Author

null-routed commented Dec 23, 2020

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
Copy link

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

@b31ngd3v
Copy link
Owner

b31ngd3v commented Dec 26, 2020

@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!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants