F#–In the Enterprise III

In our previous posts here and here, we looked at why and how F# can be used with WPF. Today we will check out how to create a real-world application using F# and WPF (with MVVM pattern). We would check this out using a video tutorial, (which is more intuitive and less time consuming to read a big post). Below is the app architecture,

App architecture Note: To start developing twitter apps, You should first get registered in dev.twitter.com and get the access token and secret.

There are three main areas that defines the application,

  1. oAuth – To get authorization with Twitter
  2. Download Agent – F# Agent worker that connects to Twitter with oAuth and parses the tweets from XML response stream.
  3. MVVM – The whole app is built around MVVM

OAuth in Twitter

OAuth requires a series of steps to execute and get the authorization key and secret. You can find more details here. In our sample we have a script file(twitter_oauth.fsx) that shows how to get the token and the secret, Execute the below code,

// Execute the below three lines first and then copy-paste the verifier code that Twitter gives you
let oauth_token'', oauth_token_secret'', oauth_callback_confirmed = OAuth.requestToken()
let url = OAuth.authorizeURI + "?oauth_token=" + oauth_token''
System.Diagnostics.Process.Start(url) |> ignore

This will start off the your browser to allow access to this app,


This will give you a “verifier” code which you need to use to get your private access token and secret.

let mutable verifier = ""
let oauth_token, oauth_token_secret = OAuth.accessToken(oauth_token'', oauth_token_secret'', verifier)
printfn "%s" oauth_token
printfn "%s" oauth_token_secret


Now  you are good to go ahead and start writing the Twitter app. The Twitter app contains an agent worker to pull the data from twitter and a simple observable collection to push the data into the UI.

We also use some async helpers that lets us marshal from background thread to the UI thread using SynchronizationContext. Check the “AsyncHelpers.fs” for more details.


F#–In the Enterprise

Download the source from here. The sample project doesn’t contain the consumer key / secret as well as the oauth key and secret, you need to manually replace them to run the application.


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: