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

# SpacesClient

> Methods for X API v2 Spaces endpoints.

Access **Spaces** endpoints via `client.spaces()` (`SpacesClient`).

## Methods

| Method | Endpoint | Behavior | Summary |
| :- | :- | :- | :- |
| [`getBuyers`](#getbuyers) | `GET /2/spaces/{id}/buyers` | Paginated | Get Space Ticket Buyers |
| [`getByCreatorIds`](#getbycreatorids) | `GET /2/spaces/by/creator_ids` | Standard | Get Spaces by Creator IDs |
| [`getById`](#getbyid) | `GET /2/spaces/{id}` | Standard | Get Space by ID |
| [`getByIds`](#getbyids) | `GET /2/spaces` | Standard | Get Spaces by IDs |
| [`getPosts`](#getposts) | `GET /2/spaces/{id}/tweets` | Paginated | Get Space Posts |
| [`search`](#search) | `GET /2/spaces/search` | Standard | Search Spaces |

## `getBuyers`

GET `/2/spaces/{id}/buyers` Paginated

**Get Space Ticket Buyers**

Retrieves a list of Users who purchased tickets to a specific Space by its ID.

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .accessToken(System.getenv("X_ACCESS_TOKEN"))
    .build();

for (var page : client.spaces().getBuyersPages("1YqKDqWLPPlGV")) {
    System.out.println(page);
}
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**Optional parameters (SpacesClient.GetBuyersOptions — 5)**

**options.maxResults** `Integer`

`max_results` (query parameter).

**options.paginationToken** `String`

A base32hex-encoded pagination token.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.postFields** `List\<String\>`

A comma separated list of Post fields to display.

**Returns:** `Schemas.GetSpacesBuyersResponse` (use `getBuyersPages(...)` for automatic `Paginator<...>` iteration)

***

## `getByCreatorIds`

GET `/2/spaces/by/creator_ids`

**Get Spaces by Creator IDs**

Retrieves details of Spaces created by specified User IDs.

```java theme={null}
import com.x.xdk.XClient;
import java.util.List;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

var response = client.spaces().getByCreatorIds(List.of("2244994945"));
System.out.println(response);
```

### Parameters

**userIds** `List\<String\>` *required*

`user_ids` (query parameter).

**Optional parameters (SpacesClient.GetByCreatorIdsOptions — 4)**

**options.spaceFields** `List\<String\>`

A comma separated list of Space fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.topicFields** `List\<String\>`

A comma separated list of Topic fields to display.

**Returns:** `Schemas.GetSpacesByCreatorIdsResponse`

***

## `getById`

GET `/2/spaces/{id}`

**Get Space by ID**

Retrieves details of a specific Space by its ID.

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

var response = client.spaces().getById("1YqKDqWLPPlGV");
System.out.println(response);
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**Optional parameters (SpacesClient.GetByIdOptions — 4)**

**options.spaceFields** `List\<String\>`

A comma separated list of Space fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.topicFields** `List\<String\>`

A comma separated list of Topic fields to display.

**Returns:** `Schemas.GetSpacesByIdResponse`

***

## `getByIds`

GET `/2/spaces`

**Get Spaces by IDs**

Retrieves details of multiple Spaces by their IDs.

```java theme={null}
import com.x.xdk.XClient;
import java.util.List;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

var response = client.spaces().getByIds(List.of("1YqKDqWLPPlGV"));
System.out.println(response);
```

### Parameters

**ids** `List\<String\>` *required*

`ids` (query parameter).

**Optional parameters (SpacesClient.GetByIdsOptions — 4)**

**options.spaceFields** `List\<String\>`

A comma separated list of Space fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.topicFields** `List\<String\>`

A comma separated list of Topic fields to display.

**Returns:** `Schemas.GetSpacesByIdsResponse`

***

## `getPosts`

GET `/2/spaces/{id}/tweets` Paginated

**Get Space Posts**

Retrieves a list of Posts shared in a specific Space by its ID.

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

for (var page : client.spaces().getPostsPages("1YqKDqWLPPlGV")) {
    System.out.println(page);
}
```

### Parameters

**id** `String` *required*

`id` (path parameter).

**Optional parameters (SpacesClient.GetPostsOptions — 8)**

**options.maxResults** `Integer`

`max_results` (query parameter).

**options.paginationToken** `String`

A base32hex-encoded pagination token.

**options.postFields** `List\<String\>`

A comma separated list of Post fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.mediaFields** `List\<String\>`

A comma separated list of Media fields to display.

**options.pollFields** `List\<String\>`

A comma separated list of Poll fields to display.

**options.placeFields** `List\<String\>`

A comma separated list of Place fields to display.

**Returns:** `Schemas.GetSpacesPostsResponse` (use `getPostsPages(...)` for automatic `Paginator<...>` iteration)

***

## `search`

GET `/2/spaces/search`

**Search Spaces**

Retrieves a list of Spaces matching the specified search query.

```java theme={null}
import com.x.xdk.XClient;

XClient client = XClient.builder()
    .bearerToken(System.getenv("X_BEARER_TOKEN"))
    .build();

var response = client.spaces().search("from:XDevelopers");
System.out.println(response);
```

### Parameters

**query** `String` *required*

`query` (query parameter).

**Optional parameters (SpacesClient.SearchOptions — 6)**

**options.state** `String`

`state` (query parameter).

**options.maxResults** `Integer`

`max_results` (query parameter).

**options.spaceFields** `List\<String\>`

A comma separated list of Space fields to display.

**options.expansions** `List\<String\>`

A comma separated list of fields to expand.

**options.userFields** `List\<String\>`

A comma separated list of User fields to display.

**options.topicFields** `List\<String\>`

A comma separated list of Topic fields to display.

**Returns:** `Schemas.SearchSpacesResponse`

***
