skip to Main Content

I’m using Twitter’s real-time filtered stream API (for the first time!) in Python, and I’m basically trying to recreate my real-time timeline in-terminal: I want to get a response every time someone I follow tweets, retweets, etc. I’m doing this in two steps:

  • GETting an id list of people I follow (my “friends”) from api.twitter.com/1.1/friends/ids.json?screen_name=my_username
  • Iterating over the returned list ids and creating a “from:” follow rule for each:
for f_id in friends_list_response['ids']:
    rule_val = "from:" + str(f_id)
    filter_rules.append({"value": rule_val, "tag": str(f_id)},)

I have this working for up to 10 test friends—they tweet, I get terminal printout in real-time. However I very quickly hit a cap, since I follow 500+ accounts, and am thus creating 500+ distinct from: rules for the filtered stream.

(HTTP 422): {"detail":"Rule creation request exceeds account’s current rule limits. Please remove or update existing rules to proceed.","title":"RulesCapExceeded","type":"https://api.twitter.com/2/problems/rule-cap"

I don’t really understand what to do about hitting my cap (that "type:" url doesn’t offer guidance). Whether I need higher permissions to the API v2, or if I need to do something with Power Track. How can I increase my rule limit, ideally tracking 1000+ accounts? I believe I have the basic developer authorization. Or, is there a workaround to a filter rule for tweets from my friends? I wish there was an endpoint that filtered tweets by everyone followed by a user.

Again, I’m a new to this API, so I appreciate any insight!

2

Answers


  1. Chosen as BEST ANSWER

    Nevermind, Tweepy's "home_timeline" function is exactly what I needed, almost a direct answer to "I wish there was an endpoint that filtered tweets by everyone followed by a user."


  2. In Twitter API v2, you can use filtered stream to follow a list of users. You can build filtered stream from rules. The limits of rules are there:

    Your rules will be limited depending on which product track you are using.
    If you are using the Standard product track at the Basic level of access, you are able to add 25 concurrent rules to your stream, and each rule can be 512 characters long.
    If you are using the Academic Research product track, you are able to add 1000 concurrent rules to your stream, and each rule can be 1024 characters long.

    So, you can add 25 concurrent rules with 512 characters for each rule. If the only filter will be users accounts or IDs, you need to calculate the number of users that fit within the character limitations.

    The average character length of the id of twitter accounts could be between 8 (older) and 18 (newest accounts). Note that you will need to add 'sfrom:' for each user, this means 6 more characters for each user account.

    If we take into account that, the average length of ID is 13, adding the 6 predecessor characters:

    512 limit characters / 19 avg characters per user ID = ~26 ID per rule

    If we have 25 rules:

    25 rules * 26 IDs per rule = ~650 IDs in total

    Note that this is approximate and you can use the account name instead of the ID.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search