a twitter tweet notifier for https://twitter.com/linustech in csharp

To create a Twitter Tweet notifier in C#, you can use the Twitter API along with a library such as Tweetinvi. Follow these steps:

  1. Create a new C# project in Visual Studio.
  2. Install the Tweetinvi library through the NuGet package manager.
  3. Create a new Twitter app on https://developer.twitter.com/ in order to obtain authentication keys.
  4. In your C# project, add the following code to authenticate your app using your Twitter API keys:
main.cs
var tweetinviSettings = new TweetinviSettings
{
   Authentication = {
      ConsumerKey = "YOUR_CONSUMER_KEY",
      ConsumerSecret = "YOUR_CONSUMER_SECRET",
      AccessToken = "YOUR_ACCESS_TOKEN",
      AccessTokenSecret = "YOUR_ACCESS_TOKEN_SECRET"
   }
};

Auth.SetUserCredentials(tweetinviSettings.Authentication.ConsumerKey, 
    tweetinviSettings.Authentication.ConsumerSecret,
    tweetinviSettings.Authentication.AccessToken,
    tweetinviSettings.Authentication.AccessTokenSecret);
492 chars
15 lines
  1. Once authenticated, you can use the Tweetinvi library to monitor a specific Twitter user's timeline for new tweets. In this example, we will monitor Linus Tech Tips' Twitter account for new tweets:
main.cs
var linusTwitterUser = User.GetUserFromScreenName("linustech");
var userStream = Stream.CreateUserStream();

userStream.TweetCreatedByAnyoneButMe += (sender, args) =>
{
    if (args.Tweet.Creator.Id == linusTwitterUser.Id)
    {
        Console.WriteLine("New tweet from Linus Tech Tips: " + args.Tweet.Text);
        // Add here your desired notification logic
    }
};

userStream.StartStream();
398 chars
14 lines
  1. Finally, you can use the notification method of your choice (e.g. email, text message, desktop notification, etc.) to notify yourself whenever a new tweet from the specified user is detected.

Note that in order to receive real-time tweet notifications, the C# program needs to remain running continuously, so it is recommended to run it on a server or a cloud platform such as Azure, AWS or Google Cloud Platform.

gistlibby LogSnag