Typed, context-aware Go client for the Meta Threads Graph API.
go get github.com/Inoue-AI/Inoue-AI-Threads-SDK/go@latestpackage main
import (
"context"
"log"
"time"
threads "github.com/Inoue-AI/Inoue-AI-Threads-SDK/go"
)
func main() {
client := threads.New(threads.ClientOptions{
AccessToken: "USER_ACCESS_TOKEN",
Timeout: 30 * time.Second,
})
defer client.Close()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
user, err := client.GetUser(ctx, "me", nil)
if err != nil {
log.Fatalf("get user: %v", err)
}
log.Printf("@%s (%s)", user.Username, user.Name)
}| Go method | Threads endpoint |
|---|---|
GetUser(ctx, userID, fields) |
GET /{user-id} |
ListPosts(ctx, params) |
GET /{user-id}/threads |
GetPost(ctx, mediaID, fields) |
GET /{media-id} |
RefreshAccessToken(ctx, params) |
GET /refresh_access_token |
- Every method takes
context.Contextfirst; cancellation propagates. - Each
*Clientowns one*http.Clientwith explicitTimeout,MaxIdleConnsPerHost, andIdleConnTimeout.http.DefaultClientis never used. defer client.Close()releases idle connections.- API errors surface as
*threads.ErrorwithStatusCode,Type,Code,Subcode,Message, andFBTraceID.
The Go SDK lives in the go/ subdirectory. The Python SDK remains under
threads/ and is unchanged. See the top-level README for the
multi-language overview.