Posting to Twitter with C#

In this post I’ll walk through the steps required to post to your own Twitter feed using C#.

Step 1:
Before you start you must register an application name with Twitter:
dev.twitter.com/apps/new

Step 2:
Open Visual Studio 2010 and, using NuGet, download and install the Twitterizer package:

Step 3:
Grant your application access to your own Twitter account. Ensure that both read and write and enabled:

Step 4:
Here’s an example of two call the library from C#:

public static void Tweet(string message)
{
    OAuthTokens tokens = new OAuthTokens();
    tokens.ConsumerKey = "***";
    tokens.ConsumerSecret = "***";
    tokens.AccessToken = "***";
    tokens.AccessTokenSecret = "***";

    IAsyncResult asyncResult = TwitterStatusAsync.Update(
        tokens,                     // The OAuth tokens
        message,                    // The text of the tweet
        null,                       // Optional parameters (none given here)
        new TimeSpan(0, 3, 0),      // The maximum time to let the process run
        updateResponse =>           // The callback method
        {
            // Handle any errors here with: updateResponse.ErrorMessage
        });
}

Resources:
Twitterizer
Twitter Developer Site

Advertisements
This entry was posted in Reference and tagged , , . Bookmark the permalink.

2 Responses to Posting to Twitter with C#

  1. Francisco Oliveira says:

    Thank you very much for this post! I was very helpful.

  2. devin says:

    thanks. this is very helpful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s