Published

Unfollow inactive twitter users using c#

As part of my efforts for continuous learning I always try to read code from others. Today I have found on Codeplex a pretty cool library that helps you with the Twitter API called Tweetinvi, which the author defines as “an intuitive C# SDK for Twitter API”.

Tweetinvi provides access to the Twitter REST API and the Twitter Stream API. It has been developed as a Portable Class Library, so it can be used from .NET Framework 4.0, Windows 8, Windows RT, Windows Phone, Mono and Android.

Just to test how it works I’ve written some basic code that helps me to unfollow inactive twitter accounts.

The first time you access you will need to create an “App” and set-up the right permissions for it, in this case we will need to Read & Write. Once you have configured the permissions request your token access. If you request a token before setting up the permissions, you will need to renew it as the token is specific to the set of permissions.

Take note of the API key, API secret, Access Token and Access token secret, as those are the values you will need to authenticate with your own twitter account.

For this example I’ve just used a console application project in Visual Studio 2013, next step is to download the latest version of Tweetinvi from Codeplex and set up the references in your project. To simplify this process, just open the “Package Manager Console” by typing “nuget console” in the “Quick Launch” (CTRL + Q). Once the console is ready, type “install-package TweetinviAPI”, this will download, install and configure Tweetinvi and all the required dependencies.

Now that all is configured, you are ready to start coding against the Twitter API.

Below you can see the methods I’ve written to unfollow the people who hasn’t been active in twitter in the last X days.