How can you automatically post message to Twitter from C#, ASP.NET MVC (from your application)?
First, setup new Twitter application under your Twitter account.
- Go to dev.twitter.com and login with your Twitter account
- Click on Add Application and enter the all needed data
You will get all all needed secret keys and tokens and they are needed for automatic tweeting.
- Consumer key: xxxxxxxxxxxxxxxxxxxxx
- Consumer secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- Access Token (oauth_token): xxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- Access Token Secret (oauth_token_secret): xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Now, download Twitterizer API
- reference Twitterizer2.dll
- Put this code into your application (of course change the location from where you get your secret keys – we have a Settings class)
public void PublishOnTwitter(string message)
{
OAuthTokens tokens = new OAuthTokens();
tokens.ConsumerKey = Settings.TwitterConsumerKey;
tokens.ConsumerSecret = Settings.TwitterConsumerSecret;
tokens.AccessToken = Settings.TwitterToken;
tokens.AccessTokenSecret = Settings.TwitterTokenSecret;
TwitterStatus status = TwitterStatus.Update(tokens, message);
}
And that’s it!
Enjoy!