I am trying to use the Twitter API to listen for new tweets matching a certain keyword, but I can't seem to get it working. I have been able to successfully push and read tweets using my API credentials, so I know that my credentials are valid.
Here is the code that I'm using:
using Tweetinvi;
using Tweetinvi.Models;
using Tweetinvi.Parameters;
var consumerKey = "Ef5KN4YsHyEPwcI77JjoPRsTw";
var consumerSecret = "mepw2bvbhaS7BqDlBupXtGrW2f0YBwebxVX932J43PxoSe6CYb";
var accessToken = "1154133280914059271-MLwk85DJekpHWYY2inGQYOF1tfeqFP";
var accessTokenSecret = "MsskhAdaRpDCUR07CgxT8r5vgNMp1X2Ohxxt826mn4slw";
var credentials = new TwitterCredentials(consumerKey, consumerSecret, accessToken, accessTokenSecret);
var client = new TwitterClient(credentials);
var stream = client.Streams.CreateFilteredStream();
stream.AddTrack("Hello, specific tweet!");
stream.MatchingTweetReceived += (sender, args) =>
{
Console.WriteLine(args.Tweet.Text);
};
stream.StartMatchingAnyConditionAsync().ConfigureAwait(false);
//i can push
client.Tweets.PublishTweetAsync(new PublishTweetParameters("Hello, specific tweet!"));
//i can read
var userTimeline = await client.Timelines.GetUserTimelineAsync("Anton99836536");
var number = userTimeline.Length;
Console.WriteLine(number);
foreach (var item in userTimeline)
{
Console.WriteLine(item.Text);
}
//i am authenticated
var user = await client.Users.GetAuthenticatedUserAsync();
Console.WriteLine(user);
When I run this code, it seems to connect to the Twitter API, but I never see any tweets being printed to the console, even though I know that there are tweets matching the keyword "Hello, specific tweet!".
Can someone help me figure out what I'm doing wrong and how I can listen for new tweets using the Twitter API?
PS I use .net core 6 console and TweetinviAPI" Version="5.0.4"
I try to get messages, that mathed to my filter.