> ## Documentation Index
> Fetch the complete documentation index at: https://docs.twexapi.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Go SDK

> Use the TwexAPI Go SDK for tweet search, follower exports, DMs, and X automation in Go services and workers.

Use the Go SDK when you want context-aware calls, typed request structs, retries, and pagination helpers for TwexAPI REST workflows in Go services and background workers.

| Go task        | SDK call               | Save         |
| -------------- | ---------------------- | ------------ |
| Search tweets  | `Search.Advanced`      | `NextCursor` |
| Read profile   | `Users.GetAbout`       | `ScreenName` |
| List followers | `Users.Followers.List` | cursor       |

## Install

```bash theme={null}
go get github.com/twexapi-dev/x-api-scraper-go@v0.1.0
```

Source: [twexapi-dev/x-api-scraper-go](https://github.com/twexapi-dev/x-api-scraper-go)

## Authenticate

```bash theme={null}
export X_API_SCRAPER_KEY="YOUR_API_KEY"
```

```go theme={null}
package main

import (
    "context"
    "os"

    xapiscraper "github.com/twexapi-dev/x-api-scraper-go"
    "github.com/twexapi-dev/x-api-scraper-go/models/components"
)

func main() {
    client := xapiscraper.New(
        xapiscraper.WithSecurity(os.Getenv("X_API_SCRAPER_KEY")),
    )

    ctx := context.Background()
    req := components.AdvancedSearchCursorQuery{
        SearchTerms: []string{"from:elonmusk"},
        SortBy:      "Latest",
        NextCursor:  "",
    }

    res, err := client.Search.Advanced(ctx, req)
    if err != nil {
        panic(err)
    }
    _ = res
}
```

## Basic example

Look up a profile and paginate followers:

```go theme={null}
about, err := client.Users.GetAbout(ctx, "elonmusk")
if err != nil {
    panic(err)
}

followers, err := client.Users.Followers.List(ctx, components.FollowersFollowingV3Query{
    Username: "elonmusk",
})
if err != nil {
    panic(err)
}
```

## Workflow: search tweets

```go theme={null}
cursor := ""
for {
    res, err := client.Search.Advanced(ctx, components.AdvancedSearchCursorQuery{
        SearchTerms: []string{"from:elonmusk AI"},
        SortBy:      "Latest",
        NextCursor:  cursor,
    })
    if err != nil {
        panic(err)
    }

    for _, tweet := range res.Tweets {
        // process tweet rows
        _ = tweet
    }

    if !res.HasNextPage || res.NextCursor == nil || *res.NextCursor == "" {
        break
    }
    cursor = *res.NextCursor
}
```

## Workflow: post a tweet

Write actions need a Twitter cookie or `auth_token` on the request:

```go theme={null}
_, err := client.Tweets.Actions.Create(ctx, components.CreateTweetRequest{
    TweetContent: "Hello from the TwexAPI Go SDK.",
    Cookie:       os.Getenv("TWITTER_COOKIE"),
})
```

## Error handling

The SDK returns typed errors for HTTP failures. Check `err` from each call and inspect status codes before retrying 4xx responses.

Configure retries with `WithRetryConfig` on the client or per-operation options.

## References

* [SDKs overview](/sdks)
* [Authentication](/authentication)
* [Terraform provider](/sdks/terraform) (wraps this Go SDK)
* [Advanced Twitter Search](/api-reference/search-endpoints/advanced-twitter-search)
* [Source Repository](https://github.com/twexapi-dev/x-api-scraper-go)
