Twitter integration in Windows 8

Integrating Twitter in your own Windows 8 store app requires a lot of knowledge of their API, this because of the strict requirement of authentication through OAuth ! We needed this twitter integration, because we want to show the twitter avatars of several users in our app!

If you are up to it, you can implement your own REST code… But if you are a bit like me and would think others are far more educated to get it right, you can go for a library that does all the hard work for you!

I choose to use Linq2Twitter ( made by @JoeMayo ) for our latest Windows 8 store application, because for me, the Linq format just seems the best way to deal with the API.

Now let me show you how you can add that twitter integration in your Windows 8 app!

First things first, when you want to do any twitter API calls from within your own app, you’ll need to register the app through their Developer site, be sure to also fill in a callback URL ! When this is done and your app was verified, you’ll get 2 keys that are needed in your .net code:

  • Consumer key
  • Consumer secret

When you have that in place, you can add the code needed to get your user to allow your app to talk with his twitter account. Within a Windows 8 store app, this  is done with the WinRtAuthorizer from Linq2Twitter. Just take care of saving the passed through user credentials, so you can reuse them the next time your app starts!

 

When this is done, you normally should have an authorized twitter context that you can use inside your app. What I needed in our app was retrieving several twitter user handle images and also needed to be able to tweet a certain text.

For searching a lot of users at the same time you can use the following code:

 

What we do here is perform a twitter lookup with a string concatenated list of twitter screen names. If the search went ok, we get back an Enumerable list of twitter Users that contain a lof of info about the user! In our case we needed the user.ProfileImageUrl

So that’s it, nothing more to it, be sure to check out the codeplex site of Linq2Twitter for much more details on what you can do with this library.