Example using F#

Jan 8 at 3:25 AM
Edited Jan 8 at 3:25 AM
I put together a simple F# program that uses the linqtotwitter library to do a simple twitter search and print the results. It uses the 3.0 beta library. It may not be optimal but it does work ;-)

I would be very interested in communication with anyone else using linqtotwitter with F#.

open LinqToTwitter
open LinqToTwitter.Security
open System.Configuration
open System.Linq

[<EntryPoint>]
let main argv = 
    
    let cs =
        { new SingleUserInMemoryCredentialStore() with
                member this.ConsumerKey = ConfigurationManager.AppSettings.Get("consumerKey")
                member this.ConsumerSecret = ConfigurationManager.AppSettings.Get("consumerSecret")
                member this.AccessToken = ConfigurationManager.AppSettings.Get("accessToken")
                member this.AccessTokenSecret = ConfigurationManager.AppSettings.Get("accessTokenSecret")
        }

    let mutable auth = new SingleUserAuthorizer() 
    auth.CredentialStore <- cs
    let twitterCtx = new TwitterContext(auth)

    let queryResults = query {
        for search in twitterCtx.Search do
        where (search.Type = SearchType.Search)
        where (search.Query = "#fsharp")
        select search
        }
//        |> Seq.toList
    let r = queryResults.Single()

    for twt in r.Statuses do
        printfn "%s - %s" twt.User.Name twt.Text

    0 // return an integer exit code
Coordinator
Jan 8 at 3:42 AM
John,

This is awesome!

@JoeMayo
Feb 10 at 11:26 PM
This is great! I will be using it and let you know how it goes!
Feb 16 at 6:34 AM
Linq2Twitter works great with my F# Console application, but I couldn't make it run in FSI (F# Interactive). I think I have all libraries loaded, but it always stuck here.
Binding session to 'G:\Bitbucket\miningthesocialweb\packages\Microsoft.Net.Http.2.2.18\lib\net45\System.Net.Http.Primitives.dll'...
#r @"System.Runtime"
#r @"System.Collections"
#r @"System.Threading.Tasks"
#r @"System.Linq.Expressions"
#r @"System.Net.Requests"
#r @"System.Linq.Expressions"
#r @"System.Runtime.Extensions"
#r @"..\packages\linqtotwitter.3.0.2\lib\net45\LinqToTwitterPcl.dll"
#r @"..\packages\Microsoft.Net.Http.2.2.18\lib\net45\System.Net.Http.Primitives.dll"

open LinqToTwitter

let twitterCredential = 
    {
        new SingleUserInMemoryCredentialStore() with 
                member this.ConsumerKey = ""
                member this.ConsumerSecret = ""
                member this.AccessToken = ""
                member this.AccessTokenSecret = "" 
    }

let mutable auth = new SingleUserAuthorizer()
auth.CredentialStore <- twitterCredential
let twitterCtx = new TwitterContext(auth)

let getTrends trend_id = 
    query {
        for trend in twitterCtx.Trends do
        where (trend.Type = TrendType.Place)
        where (trend.WoeID = trend_id)
        select trend
    }

let world_woe_id = 1

let printTrends (trends:seq<Trend>) =
    printfn "\r\nTRENDS\r\n======"
    for trend in trends do       
        printfn "Url: %s \r\nName: %s" (trend.SearchUrl) (trend.Name)


let worldTrends = getTrends world_woe_id
worldTrends |> printTrends
Have you been able to make it work? Thanks!
Coordinator
Feb 17 at 6:16 PM
Edited Feb 17 at 6:16 PM
kimsk,

LINQ to Twitter has dependencies on HttpClient, which includes System.Net.Http, System.Net.Http.Extensions, and System.Net.Http.Primitives. I'm not sure about what's causing your problems, but maybe referencing the missing assemblies might help.

@JoeMayo
Feb 17 at 11:26 PM
Thanks Joe. It could be something about how F# Interactive (FSI) works. Linq to Twitter v3.x is working fine with the F# console application.

Right now, I prefer using FSI, so I just rollback to v2.x which works just fine.

Here is a link to the code in case anyone is interesting. https://github.com/kimsk/FSharp-Mining-the-Social-Web/tree/master/src/Twitter

Thanks again for your great work!