Click here to Skip to main content
14,400,000 members

Building a C# WPF Twitter Reader with REST API (Now .NET Core 3 Version!)

Rate this:
4.57 (37 votes)
Please Sign up or sign in to vote.
4.57 (37 votes)
25 Nov 2019CPOL
Create a C# WPF app to read Twitter tweets and retweets via REST API with grouping related users / friends by categories. As a bonus, tweets can be saved in Azure / Cloud, and viewed in an Azure website.


On 11/25/2019, I added, which supports .NET Core 3.0. Major information to use the source code, and changes:

  1. Download .NET Core 3.0 SDK to compile with Visual Studio 2019.
  2. After Publish in VS 2019, a single executable can be found at TwitterReaderV2NETCore_11252019\TwitterReaderV2NETCore\bin\Release\netcoreapp3.0\publish
  3. Newtonsoft.Json is removed. The built-in System.Text.Json is used.

Please leave me messages below if you have questions about the .NET Core version.

As of 2019-03-05, a new implementation is attached for you to download: This includes a new UI (see below), and the ability to save tweets in a Microsoft Azure Service and an Azure website to view saved tweets. The Azure part is runtime only and code explanation is out of the scope of this article.

Click to enlarge image

The article's original descriptions continue as follows.

As a Twitter user, you may follow a number of interesting people and organizations to read their tweets and retweets. It can be quite helpful if you group users in categories and focus on certain types of users at a particular time, cutting down noises from the rest. If you have multiple Twitter login accounts, you may want to switch between the accounts quickly and easily.


Twitter provides a development platform for developers. You can use REST API + OAuth to access tweets and retweets:

With my app, you can read tweets and retweets with a pre-defined Twitter login I created. You can also register a Twitter app at with your own Twitter account and use the credentials to see your Twitter login in action! See TwitterCredentialsSetup.txt in download.

From a technical point of view, you can review or learn how the following techniques are being applied:

  • C# 6 / WPF / TreeView / TabControl / ListView / ContextMenu / MVVM / ...
  • REST API / OAuth / Json Serialization / HttpClient / HttpClientHandler / ...

Using the Code

When launched, the app looks like this:

Image 2

The testing login TweetTesterNET (screen name) in the dropdown list follows 7 users in 3 groups. The Generate Groups button is for a one-time function to create the 3 pre-defined groups (already done in the screenshot). If you have multiple Twitter login accounts, you can prepare them in json files to be loaded into the dropdown list.

As shown, .NET Team (@dotnet) is the selected user, and its tweets and retweets are displayed in a TabControl on the right.

There are 2 projects. TwitterAccess is a class library containing 'Twitter APIs'. TwitterReader is the WPF app.

Image 3

TweetEntity represents a tweet, containing Id, FullText, CreatedBy, etc. Entities are serialized and deserialized Newtonsoft.Json for REST API.

public class TweetEntity
    public long Id { get; set; }        
    public string FullText { get; set; }

    public UserEntity CreatedBy { get; set; }

To get tweets and retweets for a user, use this method:

public List<TweetEntity> GetUserTweetList(long userId, int count, bool includeRetweet = false)
    var twitterQuery = TwitterQuery.Create(HttpMethod.Get, TwitterConstants.UserTweetsUrl);
    twitterQuery.AddParameter("user_id", userId);
    twitterQuery.AddParameter("include_rts", includeRetweet);
    twitterQuery.AddParameter("exclude_replies", false);
    twitterQuery.AddParameter("contributor_details", false);
    twitterQuery.AddParameter("count", count);
    twitterQuery.AddParameter("trim_user", false);
    twitterQuery.AddParameter("include_entities", true);
    twitterQuery.AddParameter("tweet_mode", "extended");
    string result = ExecuteQuery(twitterQuery);
    var tweetList = JsonHelper.DeserializeToClass<List<TweetEntity>>(result);
    return tweetList ?? new List<TweetEntity>();


  • Updated with a new implementation:
  • Updated the code on 3/3/2018 to support a Twitter account with more than 100 friends
  • Updated the code to improve UI on 2/18/2018
  • Updated the code and article on 2/4/2018 for multiple Twitter login support and UI changes

I used Visual Studio 2015 and C# 6. You can download the source code and read TwitterCredentialsSetup.txt for instructions.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Peter Sun (247)
Software Developer (Senior)
United States United States
I have been a full stack Windows developer for 20+ years and is based in Orange County, California. Currently, I am focusing on C#, WPF, Azure, .NET Core, and Xamarin.

Comments and Discussions

QuestionMessage Closed Pin
8-Dec-19 23:57
Memberrizwanali208-Dec-19 23:57 
QuestionLogin etc Pin
John Shutt27-Nov-19 9:15
MemberJohn Shutt27-Nov-19 9:15 
AnswerRe: Login etc Pin
Peter Sun (247)27-Nov-19 16:51
MemberPeter Sun (247)27-Nov-19 16:51 
QuestionI so want to like this but it feels a tad under explained PinPopular
Sacha Barber8-Oct-18 9:50
MemberSacha Barber8-Oct-18 9:50 
AnswerRe: I so want to like this but it feels a tad under explained Pin
Peter Sun (247)8-Oct-18 11:28
MemberPeter Sun (247)8-Oct-18 11:28 
GeneralRe: I so want to like this but it feels a tad under explained Pin
Sacha Barber8-Oct-18 21:14
MemberSacha Barber8-Oct-18 21:14 
QuestionPulling New Twitter Posts Pin
Hyland Computer Systems17-Aug-18 9:28
MemberHyland Computer Systems17-Aug-18 9:28 
AnswerRe: Pulling New Twitter Posts Pin
Peter Sun (247)20-Aug-18 20:23
MemberPeter Sun (247)20-Aug-18 20:23 
GeneralMy vote of 4 Pin
liveoffedge11-Aug-18 23:01
professionalliveoffedge11-Aug-18 23:01 
GeneralRe: My vote of 4 Pin
Peter Sun (247)12-Aug-18 18:24
MemberPeter Sun (247)12-Aug-18 18:24 
PraiseGreat WPF example Pin
Ira M Nye23-Feb-18 9:11
MemberIra M Nye23-Feb-18 9:11 
GeneralRe: Great WPF example Pin
Peter Sun (247)23-Feb-18 19:28
MemberPeter Sun (247)23-Feb-18 19:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 30 Jan 2018


90 bookmarked