How to get twitter tweets in C# Console Application Using API

By Dipak Shaw

July 11, 2020


API, ASP.NEt, C#, Console, Microsoft, Twitter, Visual Studio

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.

Click Create new Project
Select Console App either from Recent or search

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.

I’m attaching codes pic because I want you to write your own so that you”ll learn
  1. This is the authorizer to bypass the twitter authentication process.
  2. 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.
  3. 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:

As you can see top 10 recent tweets are displaying in Console Application.

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. 🙏🙏

Leave a Reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}