Hello.

I have a Twitter bot (used for @adofanbot & @rosufanbot) that reads a filtered stream (API 2.0) and RTs / translates (API 1.1) that stopped working.

I am quite new to internet things and Twitter and its API, so I’m using twitter-api-v2 from npmjs. However, I can reproduce the problem using curl.

  1. I can successfully connect to the stream. It returns an empty newline every ~15-30 seconds.
  2. Using curl, I can see the simple stream rule I’m using for testing …
    {“data”:[{“id”:“1511619147997716480”,“value”:“from:#######”,“tag”:“#######”}],“meta”:{“sent”:“2022-04-06T09:11:02.312Z”,“result_count”:1}}
  3. :sob: When I write a test tweet that matches the stream rule, the tweet is not returned by the filtered stream.
  4. I tried deleting my apps and re-creating a new app, and refreshing its bearer token.
  5. I have API 1.1 and API 2.0 access.
  6. I can post things just fine with API 1.1.
  7. Sample stream works OK.

Any tips?
Thanks …

P.S.: The Twitter Bot is called: “ファンBot” … The previous bot that stopped working is now called " “erased22785270_eDiY4izzI7”.

5 Likes

we’re finding the same problem; everything looks ok with the App but we’re not getting any tweets from the filtered stream. I hope you get an answer!

1 Like

Same problem here, looks like the issue started appearing around 14-16 hours ago. The endpoint seems to work okay, I get the normal “keepalive” messages every 20 seconds, but I don’t get any tweets. Tried recreating the app but no luck so far.

1 Like

I have this same problem.
I have spent hours trying to fix it. If we are all having the same problem then this might be related to Twitter, which means that Twitter owes me for the heartache and headache of this day :angry:

2 Likes

Same problem here. Will add some more details for Twitter to troubleshoot on their side:

We have an app with two environments (one for staging and one for production). Yesterday night, data stopped coming in on the production environment, but continued to come in on the staging environment, through the ‘rules’ were exactly the same. To further investigate, I set a rule that should return a lot of data, and used to below script to connect to the streaming API:

import requests
import argparse
import time
import json
import datetime


def main():
    aparser = argparse.ArgumentParser(
        description='Twitter Filtered stream connection test'
    )
    aparser.add_argument(
        'bearer_token',
        help=(
            'The bearer_token for the connection to twitter'
        ),
        type=str
    )

    args = aparser.parse_args()
    bearer_token = args.bearer_token

    session = requests.Session()
    session.headers.update({
        "Authorization": "Bearer {}".format(bearer_token),
        "User-Agent": "connectiontest_x26x55d"
    })

    # Get the rules, to print
    response = session.get(
        'https://api.twitter.com/2/tweets/search/stream/rules'
    )
    print('Using the following rules:')
    print(response.text)

    # Now start consuming. Just print id's to make sure it doesn't lag
    params = {
        'expansions': 'attachments.media_keys,author_id,geo.place_id',
        'user.fields': 'id,location,name,username',
        'media.fields': 'type,url,preview_image_url',
        'place.fields': 'full_name,geo,id,place_type',
        'tweet.fields': 'attachments,author_id,created_at,id,text,lang'
    }
    with session.get(
                'https://api.twitter.com/2/tweets/search/stream',
                stream=True, timeout=(1, 21),
                params=params
            ) as response:
        if response.status_code != 200:
            raise requests.exceptions.HTTPError(
                'Initial stream connection failed with code {}: {}'.format(
                    response.status_code, response.text
                ),
                response=response
            )

        for response_line in response.iter_lines():
            if response_line:  # Also emtpy keep-alive signals are sent
                payload = json.loads(response_line)
                if 'data' in payload:
                    created_at = datetime.datetime.fromisoformat(
                        payload['data']['created_at'].rstrip('Z')
                    )
                    delay = (datetime.datetime.utcnow() - created_at).total_seconds()
                    print(
                        f"{int(time.time())}: "
                        f"Received id {payload['data']['id']}"
                        f" with delay {delay}"
                    )
                else:
                    # e.g. errors
                    print(f"{int(time.time())}: {payload}")
            else:
                print(f"{int(time.time())}: Received empty line")


if __name__ == '__main__':
    main()

I set the simple rule flood -is:retweet, which should return tweets on average every 5 seconds or so, but the output is the following:

python basic_test.py "REDACTED_BEARER_TOKEN"
Using the following rules:
{"data":[{"id":"1511678065394524165","value":"flood -is:retweet"}],"meta":{"sent":"2022-04-06T12:11:59.727Z","result_count":1}}
1649247140: Received empty line
1649247160: Received empty line
1649247180: Received empty line
1649247200: Received empty line
1649247220: Received empty line
1649247240: Received empty line
1649247260: Received empty line

As can be seen above, the script does have a connection, and does receive the keep-alive signals, but no actual data is being received. I used the bearer token of the actual production environment to test. The staging environment under the same project does not have issues.

@jessicagarson Can you perhaps forward the issues we’re seeing to the relevant support team?

Please note I experienced a similar issue a few months ago, in which case the staging environment was not getting data, but the production environment was getting it…

3 Likes

@Inu @pacunar @davidbmaier @JoIyke @crocano861

I found a (hopefully temporary) workaround to get things working again.

I’ve tested the following:

  1. Regenerating the bearer_token
  2. Creating a new app under the same project (new environment)

(1) Did not help, and gave the same results (no data being streamed), but (2) Creating a new app/environment under the same project worked for me.

After creating the new project, use the ‘bearer_token’ in your code. You may have to wait a minute (You’ll get a 503 error stating that it’s being provisioned), but afterwards there was again data coming in for me.

@ Twitter support: Please let us know once this is fixed, so we can start using the existing app again…

3 Likes

Thanks @TomBrouwr ! we will test this. I have also been advised to test with our staging app (in the same project), so this is probably a good temporary solution. We’ll test now and let you all know if it works for us too.
In any case, this is something that Twitter needs to solve ASAP.

1 Like

Interesting that this helped you, I already tried both of those earlier today with no luck sadly.
Still not getting a single message on both my prod and dev accounts.

I also tried regenerating the bearer token, deleting all my apps and creating new ones, but still getting only keep-alive signals. However, I did test a coworker’s developer account with the same rules for filtered_stream, and appeared to work without issues. The problem might be only affecting a portion of all developer accounts.

Interestingly my Crypto Bots are still working, however my non-crypto bots are a no go. The non-working ones last worked at 4pm ish CST yesterday.

Interesting. In my case I was not using all 3 environments for the project, so I was able to create a new one. Perhaps results are different if you’re creating a new app for an environment that was already previously used?

There is an issue being tracked here - it affects some accounts and not others, not a generalised outage. Apologies for the disruption.

2 Likes