Updating Twitter status with Linq2Twitter

Published on Wednesday, September 2, 2015

So out of pure curiosity I started to think, how hard would it be to implement a twitter update for every new blog post that I do on this website? Turns out it's simplicity itself.

Start by logging in to the twitter developer site and create a new application by filling out all the necessary information in the "Create an application" form.

Step 1

Secondly after the application has been added to your account, you need to create access tokens for the application. You do this on the application page with the button marked with "Create my access tokens".

Step 2

From the application page copy the "Consumer key", "Consumer secret", "Access token" and the "Access token secret".

Now grab a copy of Linq2twitter either from their codeplex page or from the nuget repository and either create application settings as I've done below or just use the keys directly.

var auth = new SingleUserAuthorizer {
	Credentials = new InMemoryCredentials
		ConsumerKey = ConfigurationManager.AppSettings["Twitter:ConsumerKey"],
		ConsumerSecret = ConfigurationManager.AppSettings["Twitter:ConsumerSecret"],
		AccessToken = ConfigurationManager.AppSettings["Twitter:AccessTokenSecret"],
		OAuthToken = ConfigurationManager.AppSettings["Twitter:AccessToken"]

// Will throw exception if there are missing authentication
// settings.

using (var context = new TwitterContext(auth))
	context.UpdateStatus("My awesome tweet");

As you run the code there should now be a new tweet on your twitter account!


Dev Twitter Linq2Twitter

comments powered by Disqus