redouane59 / twittered

Twitter API client for Java developers
Apache License 2.0
238 stars 65 forks source link

startFilteredStream without filters set? #351

Closed consal closed 2 years ago

consal commented 2 years ago

Hello! Is it possible to use startFilteredStream without setting filters before (with addFilteredStreamRule)? For me, if there are no filters, there is no response at all. In CLI, trying with curl and no filters, it returns plenty of tweets. curl -X GET -H "Authorization: Bearer $BEARER_TOKEN" "https://api.twitter.com/2/tweets/sample/stream"

redouane59 commented 2 years ago

Hello @consal , honestly I never tested this use case before, if it is working from CLI but not in the library, that's probably a bug. I'm in travel right now but I'll try to check in the next following days :)

redouane59 commented 2 years ago

I didn't find anything in the code who can explain that. Just created a post on Twitter Forum there : https://twittercommunity.com/t/filtered-stream-without-rules/164922

igorbrigadir commented 2 years ago

The sample stream is a different endpoint, and returns random 1% of all public tweets, while the filter stream returns tweets that match the rules only. If there are no rules or you delete rules while the stream is open, I think it just sends nothing.

redouane59 commented 2 years ago

Ohhh well seen @igorbrigadir ! @consal you were looking for another method, which is startSampledStream no ? See : https://github.com/redouane59/twittered/blob/f6c6fea028ead7086454a3329acacdd6bd485601/src/main/java/io/github/redouane59/twitter/ITwitterClientV2.java#L259

consal commented 2 years ago

Oh, nice! Let me try the sampled stream and I'll let you know if it works!

consal commented 2 years ago

Unfortunately the Sampled stream doesn't seem to work, the code:

TwitterClient twitterClient = new TwitterClient(TwitterCredentials.builder()
            .bearerToken(bearerToken).build());

Future<Response> future = twitterClient.startSampledStream((Tweet tweet) -> {
            logger.info("from:@" + tweet.getUser().getName() + " : " + tweet.getText());
        });

The stream doesn't return anything, it immediately returns. Adding future.get() doesn't change anything. The same code changed to startFilteredStream with adding some filters works.

redouane59 commented 2 years ago

Juste used your code on my side and it is correctly working :

image

Are you sure you are outside a unit test ? You need to run it from a Main class :)

consal commented 2 years ago

Today I reran exactly the same code and it's working 😅 No idea what I was doing wrong yesterday. Anyway, thanks so much for your help!