Thursday 30 May 2013

Twitter Posting from Asp.net Website - Twitterizer Open Source Tutorial

Twitter Posting from Asp.net Website - Twitterizer Open Source Tutorial


Before started discussing about Twitter Programming.  Following is small description about Twitter.  "Twitter is a service for friends, family, and co–workers to communicate and stay connected through the exchange of quick, frequent answers to one simple question"  As Twitter is gaining more and more popularity, it is necessary for web master to put all the websites update on Twitter to attract more audience. 

This post will explain, How to post message from your asp.net website to Twitter.

To demonstrate this, I would be taking help of Open Source Project which easy, fast and efficient to use.  

Open Source Project for Twitter Programming in .Net : Twitterizer

Twitterizer is
.net project provides an easy to use, object-oriented interface to twitter's online API.  

Practical Example for Twitter Programming in .Net


Step2: Create New Asp.net Website. 

Step 3: Arrange the Web Controls as shown in Figure.
Step 4: Add Twitterizer Reference.
Right Click Website in Solution Explorer, and select "Add Reference" from Popup dialog.
Add the Twitterizer.Framework.dll which you have downloaded in Step1.

Step 5: Write Code.
Add Namespace: using Twitterizer.Framework;

Add following code on Shout button click event.
protected void btnShout_Click(object sender, EventArgs e)
{   
string TwitterUserName = "twitasp";
string TwitterPassword = "mypassword";
string TwitterMessage = txtShout.Text;

if (TwitterUserName != string.Empty && TwitterPassword != string.Empty)
{
try
{

Twitter twitter = new Twitter(TwitterUserName,TwitterPassword);

string TwitterMsg = txtShout.Text;
if (txtShout.Text.Length > 120)
{
TwitterMsg = TwitterMsg.Substring(0, 130) + "... For more update logon to DailyFreeCode.com";
}
else
{
TwitterMsg = TwitterMsg + "... For more update logon to DailyFreeCode.com";
}
twitter.Status.Update(TwitterMsg);
lblTwitMsg.Text = "Your have shout successfully on http://twitter.com/" + TwitterUserName;

}
catch (Exception ex)
{
Response.Write("<b>" + ex.Message + "</b><br>" + ex.StackTrace);
}
}
}

Lets Post one Message from Asp.net Website Developed.
Type your Message in Textbox and Press Shout button, you can then check your Twitter website to check whether update is applied or not.

Now Press "Shout on Twitter!" button

Now check the Twitter Website for Profile we have Shout on.
http://twitter.com/twitasp

No comments:

Post a Comment