Header menu logo Threads

Getting Started

In order to use Threads.Lib, you will need to obtain an access token from the Threads API. The Threads API use OAuth2 for authentication, so you will need to follow their documentation on this area.

For more information please visit https://developers.facebook.com/docs/threads/get-started/get-access-tokens-and-permissions

For development purposes, you can generate an access token from the apps dashboard in the facebook developers website. https://developers.facebook.com/apps/YOUR_APP_ID/use_cases/customize/?use_case_enum=THREADS_API&selected_tab=settings&product_route=threads-api

Once you have obtained an access token, you can start using Threads.Lib.

Please note that all the examples through this documentation will use F# scripts so you can run this code locally yourself, keep in mind that the version referenced in the scripts may be outdated in the documentation.

Please make sure of the latest version in the Nuget Package.

Usage

Threads.Lib is a dotnet library which is currently not compatible with the Fable Compiler so it can only be used in dotnet projects at the moment.

#r "nuget: Threads.Lib"

open System
open Threads.Lib
open Threads.Lib.Profile

let accessToken = "YOUR_ACCESS_TOKEN"
let client = Threads.Create(accessToken)

task {
  let! (response: ProfileValue seq) =
    threads.Profile.FetchProfile(
      profileId = "me",
      profileFields = [
        ProfileField.Id
        ProfileField.Username
        ProfileField.ThreadsBiography
        ProfileField.ThreadsProfilePictureUrl
      ]
    )

    printfn $"%A{response}"
    (*
      [ ProfileValue.Id "1234567890"
        ProfileValue.Username "johndoe"
        ProfileValue.ThreadsBiography "I'm a cool guy"
        ProfileValue.ThreadsProfilePictureUrl (Uri "https://example.com/picture.jpg")
      ]
    *)
}
|> Async.AwaitTask
// Note that this is just for the F# scripts environment. Projects usually don't have to call this.
|> Async.RunSynchronously

*NOTE*: The profileId "me" is a special keyword that represents the current user's profile. In order to fetch another user's profile, you will need to replace "me" with the user's id.

And just like that you now have the token owner's profile information.

In general the Library contains 5 major services that correspond to the majority of the Threads Web API.

namespace System
val accessToken: string
val client: obj
val task: TaskBuilder
val response: 'a
Multiple items
val seq: sequence: 'T seq -> 'T seq

--------------------
type 'T seq = Collections.Generic.IEnumerable<'T>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Multiple items
type Async = static member AsBeginEnd: computation: ('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit) static member AwaitEvent: event: IEvent<'Del,'T> * ?cancelAction: (unit -> unit) -> Async<'T> (requires delegate and 'Del :> Delegate) static member AwaitIAsyncResult: iar: IAsyncResult * ?millisecondsTimeout: int -> Async<bool> static member AwaitTask: task: Task<'T> -> Async<'T> + 1 overload static member AwaitWaitHandle: waitHandle: WaitHandle * ?millisecondsTimeout: int -> Async<bool> static member CancelDefaultToken: unit -> unit static member Catch: computation: Async<'T> -> Async<Choice<'T,exn>> static member Choice: computations: Async<'T option> seq -> Async<'T option> static member FromBeginEnd: beginAction: (AsyncCallback * obj -> IAsyncResult) * endAction: (IAsyncResult -> 'T) * ?cancelAction: (unit -> unit) -> Async<'T> + 3 overloads static member FromContinuations: callback: (('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) -> Async<'T> ...

--------------------
type Async<'T>
static member Async.AwaitTask: task: Threading.Tasks.Task -> Async<unit>
static member Async.AwaitTask: task: Threading.Tasks.Task<'T> -> Async<'T>
static member Async.RunSynchronously: computation: Async<'T> * ?timeout: int * ?cancellationToken: Threading.CancellationToken -> 'T

Type something to start searching.