Lei Wu, Web Developer

Keeping simple things simple.

Using F# Twitter Type Provider

Recently I have been using F# a lot at work.

One of the things I love most about F# is Type Providers. Combined with Intellisense in Visual Studio, it’s very convenient for certain tasks, such as accessing Twitter account.

Today I need to find out the account information of a given Twitter account. But I only have the following information from a C# application:

ConsumerKey, ConsumerSecret, AccessToken, OAuthToken.

F# Twitter Type Provider to the rescue.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#if INTERACTIVE
#I @"..\packages\FSharp.Data.Toolbox.Twitter.0.19\lib\net40\"
#I @"..\packages\FSharp.Data.2.4.2\lib\net45\"
#r "FSharp.Data.Toolbox.Twitter.dll"
#r "FSharp.Data.dll"
#else
module Twitter
#endif

open FSharp.Data.Toolbox.Twitter

let key = "..."
let secret = "..."
let accessToken = "..."
let oauthToken = "..."

let twitter = Twitter.AuthenticateAppSingleUser(key, secret, accessToken, oauthToken)
twitter.RequestRawData("https://api.twitter.com/1.1/account/verify_credentials.json", []) |> printfn "%A"