I’m trying to build a bot using Twitter API. I’m testing Filtered stream to read the latest tweets with some words.
To test I create a single rule with a trending topic from Brasil:
{ "data": [ { "id": "1360964144200110081", "value": "carnaval lang:pt", "tag": "Carnaval" } ], "meta": { "sent": "2021-02-14T15:47:31.321Z" } }
But when I execute the GET Stream https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream
, it never returns. I believe this can be a WebSocket, but I can’t find that information on docs.
I’m doing a request on https://api.twitter.com/2/tweets/search/stream?tweet.fields=created_at&expansions=author_id&user.fields=created_at
using the Authorization token and I’m getting 200 as a response, but the connection is never closed and no content.
I’m using the following code to call: github.com/vepo/twitter4j
Advertisement
Answer
Solved!
The problem is that I was expecting a String, but, as it is a WebSocket, the Response never ends. I change it to an InputStream and it starts working.