In this example app, I’ll create a console application using C# that can read top 10 tweets of the user whose tweets you want to see. So, I’ll start step by step-
Pre-requisites: 1. An approved twitter developer account.
2. Visual Studio wit C#, .Net workloads
An approved twitter developer account:
go to https://developer.twitter.com/en and Create an app to get twitter API keys.
Creating App in Visual Studio
Open Visual Studio then select Create new Project and select Console App(.NET Framework) and give a name to your app whatever you want. Select Create.
After creating the project now, we need to write some codes to get tweets from twitter API but first we need to install NuGet package to work with twitter API. Select Tools > NuGet Package Manager > Package Manager Console and write the below command-
Install-Package linqtotwitter
After installing, our project is ready to work with twitter API. Now write the below code in the Main Method.
- This is the authorizer to bypass the twitter authentication process.
- Declaring a Twitter Context so that we can access it later to get tweets. Also declaring a user Input variable so that user can enter username whose tweets he/she wants to see.
- Using Query syntax to get tweets that matches with user input and then setting the tweets limit to 10 so that only 10 tweets will show.
At last we are using foreach loop to show each tweet one by one in console. The Console app will show user’s Name and tweeted text.
That’s it. the app is completed; Now run it and enter “microsoft” (without quotes)
Output:
You can find that project in GitHub by clicking this link – https://github.com/Dips97/GetTweetsInConsole
Well, That’s the end of this post. Let me know if you have any query or suggestion in comment below. I’ll see you next time. 🙏🙏