Header menu logo Threads

Post a Thread

Posting a thread is a two step process, create the post and then publish it

#r "nuget: Threads.Lib"

open
open Threads.Lib
open Threads.Lib.Posts

let client = Threads.Create("acces_token")
task {

  let! containerId =
    // create a container with all of the requred parameters
    client.Posts.PostContainer(
      "me",
      [ MediaType Posts.Text; Text "This is the content of the new post!" ]
    )

  // publish the container's id to the threads web api.
  let! postId = client.Posts.PublishPost("me", containerId)

  // fetch the newly created post!
  let! results =
    client.Media.FetchThread(
      postId.id,
      [
        Media.ThreadField.Id
        Media.ThreadField.Username
        Media.ThreadField.Text
        Media.ThreadField.Timestamp
        Media.ThreadField.Permalink
      ]
    )

  // for single posts, the result is a list containing
  // the requested parameters
  for result in results do
    printfn $"%A{result}"
  (*
      Id "012345678901234567"
      Permalink https://www.threads.net/@user_handle/post/ShOrTcOdE
      Username "user_handle"
      Text "This is the content of the new post!"
      Timestamp 11/6/2024 3:30:46 AM +00:00
  *)
}
|> Async.AwaitTask
|> Async.RunSynchronously
val client: obj
val task: TaskBuilder
val containerId: obj
val postId: obj
val results: obj seq
val result: obj
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: System.Threading.Tasks.Task -> Async<unit>
static member Async.AwaitTask: task: System.Threading.Tasks.Task<'T> -> Async<'T>
static member Async.RunSynchronously: computation: Async<'T> * ?timeout: int * ?cancellationToken: System.Threading.CancellationToken -> 'T

Type something to start searching.