Building a C# WPF Twitter Reader with REST API

View: 341    Dowload: 1   Comment: 0   Post by: admin   Category: Visual studio & .NET   Fields: Other

Download  building-a-c-wpf-twitter.rar (579.79 KB)

You need to Sign In to download the file building-a-c-wpf-twitter.rar
If you do not have an account then Sign up for free here

Create a C# WPF app to read Twitter tweets and retweets via REST API with grouping related users / friends by categories


(A quick note: if you downloaded this app's souce code before, it's been updated.)

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: https://developer.twitter.com.

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 https://apps.twitter.com 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:

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 TabControlon the right.

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

TweetEntity represents a tweet, containing IdFullTextCreatedBy, 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 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>(result);
    return tweetList ?? new List();

Building a C# WPF Twitter Reader with REST API

Create a C# WPF app to read Twitter tweets and retweets via REST API with grouping related users / friends by categories

Posted on 26-03-2018 


To comment you must be logged in members.

Files with category

File suggestion for you
File top downloads
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd