> ## 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.

# PostsClient

> Methods for X API v2 Posts endpoints.

Access **Posts** endpoints via `client.posts` (`PostsClient`).

## Methods

| Method | Endpoint | Behavior | Summary |
| :- | :- | :- | :- |
| [`create`](#create) | `POST /2/tweets` | Standard | Create or Edit Post |
| [`create_post_draft`](#create_post_draft) | `POST /2/posts/drafts` | Standard | Create Post Draft |
| [`delete`](#delete) | `DELETE /2/tweets/{id}` | Standard | Delete Post |
| [`delete_post_draft`](#delete_post_draft) | `DELETE /2/posts/drafts/{id}` | Standard | Delete Post Draft |
| [`get_analytics`](#get_analytics) | `GET /2/tweets/analytics` | Standard | Get Post Analytics |
| [`get_by_id`](#get_by_id) | `GET /2/tweets/{id}` | Standard | Get Post by ID |
| [`get_by_ids`](#get_by_ids) | `GET /2/tweets` | Standard | Get Posts by IDs |
| [`get_counts_all`](#get_counts_all) | `GET /2/tweets/counts/all` | Paginated | Get Count of All Posts |
| [`get_counts_recent`](#get_counts_recent) | `GET /2/tweets/counts/recent` | Paginated | Get Count of Recent Posts |
| [`get_liking_users`](#get_liking_users) | `GET /2/tweets/{id}/liking_users` | Paginated | Get Liking Users |
| [`get_post_drafts`](#get_post_drafts) | `GET /2/posts/drafts` | Paginated | Get Post Drafts |
| [`get_quoted`](#get_quoted) | `GET /2/tweets/{id}/quote_tweets` | Paginated | Get Quoted Posts |
| [`get_reposted_by`](#get_reposted_by) | `GET /2/tweets/{id}/retweeted_by` | Paginated | Get Reposted By |
| [`get_reposts`](#get_reposts) | `GET /2/tweets/{id}/retweets` | Paginated | Get Reposts |
| [`hide_reply`](#hide_reply) | `PUT /2/tweets/{tweet_id}/hidden` | Standard | Hide Reply |
| [`search_all`](#search_all) | `GET /2/tweets/search/all` | Paginated | Search All Posts |
| [`search_recent`](#search_recent) | `GET /2/tweets/search/recent` | Paginated | Search Recent Posts |

## `create`

POST `/2/tweets`

**Create or Edit Post**

Creates a new Post for the authenticated user, or edits an existing Post when edit\_options are provided. Media in media.media\_ids is attached in the order given; get the ids by uploading each image with Upload Media, or a video with Initialize Media Upload. Supports paid partnership disclosure via the paid\_partnership field. To share a clip of another Post's video, set clip to that Post's id and a range of 5 to 60 seconds.

```python theme={null}
import os
from xdk import Client
from xdk.posts.models import CreateRequest

client = Client(access_token=os.environ["X_ACCESS_TOKEN"])

response = client.posts.create(body=CreateRequest(text="Hello from XDK!"))
print(response)
```

### Parameters

**body** `CreateRequest` *required*

Request payload.

**Returns:** `CreateResponse`

***

## `create_post_draft`

POST `/2/posts/drafts`

**Create Post Draft**

Saves a Post draft to the authenticated user's X account without publishing it. Takes the body of Create or Edit Post, of which a draft stores text, media with tagged users, a reply and the AI and paid partnership disclosures. Any other field that is set is a 400 that names it.

```python theme={null}
import os
from xdk import Client
from xdk.posts.models import CreatePostDraftRequest

client = Client(access_token=os.environ["X_ACCESS_TOKEN"])

response = client.posts.create_post_draft(body=CreatePostDraftRequest(text="Hello from XDK!"))
print(response)
```

### Parameters

**body** `CreatePostDraftRequest` *required*

Request payload.

**Returns:** `CreatePostDraftResponse`

***

## `delete`

DELETE `/2/tweets/{id}`

**Delete Post**

Deletes a specific Post by its ID, if owned by the authenticated user.

```python theme={null}
import os
from xdk import Client

client = Client(access_token=os.environ["X_ACCESS_TOKEN"])

response = client.posts.delete(id="1895000000000000000")
print(response)
```

### Parameters

**id** `schemas.PostId` *required*

`id` (path parameter).

**Returns:** `DeleteResponse`

***

## `delete_post_draft`

DELETE `/2/posts/drafts/{id}`

**Delete Post Draft**

Deletes one of the authenticated user's Post drafts by its ID. The whole draft is deleted, including any part Get Post Drafts does not list, and cannot be restored. An ID that is not one of the user's drafts also returns deleted: true.

```python theme={null}
import os
from xdk import Client

client = Client(access_token=os.environ["X_ACCESS_TOKEN"])

response = client.posts.delete_post_draft(id="1895000000000000000")
print(response)
```

### Parameters

**id** `str` *required*

The ID of the draft to delete.

**Returns:** `DeletePostDraftResponse`

***

## `get_analytics`

GET `/2/tweets/analytics`

**Get Post Analytics**

Retrieves analytics data for specified Posts within a defined time range.

```python theme={null}
import os
from xdk import Client

client = Client(access_token=os.environ["X_ACCESS_TOKEN"])

response = client.posts.get_analytics(
    ids=["1895000000000000000"],
    start_time="2026-01-01T00:00:00Z",
    end_time="2026-01-02T00:00:00Z"
)
print(response)
```

### Parameters

**ids** `List[schemas.AnalyticsId]` *required*

`ids` (query parameter).

**start\_time** `str` *required*

`start_time` (query parameter).

**end\_time** `str` *required*

`end_time` (query parameter).

**Optional keyword arguments (2)**

**granularity** `Literal["hourly", "weekly", "daily", "total"]`

`granularity` (query parameter).

**analytics\_fields** `List[Literal["app_install_attempts", "app_opens", "bookmarks", "detail_expands", "email_tweet", "engagements", "follows", "hashtag_clicks", "id", "impressions", "likes", "media_views", "permalink_clicks", "quote_tweets", "replies", "retweets", "shares", "timestamp", "timestamped_metrics", "unfollows", "unlikes", "url_clicks", "user_profile_clicks"]]`

A comma separated list of Analytics fields to display.

**Returns:** `GetAnalyticsResponse`

***

## `get_by_id`

GET `/2/tweets/{id}`

**Get Post by ID**

Retrieves details of a specific Post by its ID.

```python theme={null}
import os
from xdk import Client

client = Client(bearer_token=os.environ["X_BEARER_TOKEN"])

response = client.posts.get_by_id(id="1895000000000000000")
print(response)
```

### Parameters

**id** `schemas.PostId` *required*

`id` (path parameter).

**Optional keyword arguments (6)**

**post\_fields** `List[Literal["article", "article_title", "attachments", "card_uri", "community_id", "context_annotations", "conversation_id", "created_at", "display_text_range", "edit_controls", "entities", "geo", "id", "lang", "matched_media_notes", "media_metadata", "non_public_metrics", "note_post", "note_request_suggestions", "organic_metrics", "paid_partnership", "possibly_sensitive", "promoted_metrics", "public_metrics", "reply_settings", "scopes", "source", "suggested_source_links", "suggested_source_links_with_counts", "text", "withheld"]]`

A comma separated list of Post fields to display.

**expansions** `List[Literal["article.cover_media", "article.media_entities", "attachments.media_keys", "attachments.media_source_tweet", "attachments.poll_ids", "author_id", "edit_history_post_ids", "entities.mentions.username", "geo.place_id", "in_reply_to_user_id", "referenced_posts", "username"]]`

A comma separated list of fields to expand.

**user\_fields** `List[Literal["active_follower_count", "confirmed_email", "connection_status", "created_at", "description", "entities", "id", "is_identity_verified", "location", "name", "org_only", "parody", "profile_banner_url", "profile_image_url", "protected", "public_metrics", "receives_your_chat", "receives_your_dm", "subscriber_count", "subscribes_to_you", "subscription", "subscription_type", "url", "username", "verified", "verified_followers_count", "verified_type", "withheld"]]`

A comma separated list of User fields to display.

**media\_fields** `List[Literal["alt_text", "duration_ms", "height", "media_key", "non_public_metrics", "organic_metrics", "preview_image_url", "promoted_metrics", "public_metrics", "revenue", "type", "url", "variants", "width"]]`

A comma separated list of Media fields to display.

**poll\_fields** `List[Literal["duration_minutes", "end_datetime", "id", "options", "voting_status"]]`

A comma separated list of Poll fields to display.

**place\_fields** `List[Literal["contained_within", "country", "country_code", "full_name", "geo", "id", "name", "place_type"]]`

A comma separated list of Place fields to display.

**Returns:** `GetByIdResponse`

***

## `get_by_ids`

GET `/2/tweets`

**Get Posts by IDs**

Retrieves details of multiple Posts by their IDs.

```python theme={null}
import os
from xdk import Client

client = Client(bearer_token=os.environ["X_BEARER_TOKEN"])

response = client.posts.get_by_ids(ids=["1895000000000000000"])
print(response)
```

### Parameters

**ids** `List[schemas.PostId]` *required*

`ids` (query parameter).

**Optional keyword arguments (6)**

**post\_fields** `List[Literal["article", "article_title", "attachments", "card_uri", "community_id", "context_annotations", "conversation_id", "created_at", "display_text_range", "edit_controls", "entities", "geo", "id", "lang", "matched_media_notes", "media_metadata", "non_public_metrics", "note_post", "note_request_suggestions", "organic_metrics", "paid_partnership", "possibly_sensitive", "promoted_metrics", "public_metrics", "reply_settings", "scopes", "source", "suggested_source_links", "suggested_source_links_with_counts", "text", "withheld"]]`

A comma separated list of Post fields to display.

**expansions** `List[Literal["article.cover_media", "article.media_entities", "attachments.media_keys", "attachments.media_source_tweet", "attachments.poll_ids", "author_id", "edit_history_post_ids", "entities.mentions.username", "geo.place_id", "in_reply_to_user_id", "referenced_posts", "username"]]`

A comma separated list of fields to expand.

**user\_fields** `List[Literal["active_follower_count", "confirmed_email", "connection_status", "created_at", "description", "entities", "id", "is_identity_verified", "location", "name", "org_only", "parody", "profile_banner_url", "profile_image_url", "protected", "public_metrics", "receives_your_chat", "receives_your_dm", "subscriber_count", "subscribes_to_you", "subscription", "subscription_type", "url", "username", "verified", "verified_followers_count", "verified_type", "withheld"]]`

A comma separated list of User fields to display.

**media\_fields** `List[Literal["alt_text", "duration_ms", "height", "media_key", "non_public_metrics", "organic_metrics", "preview_image_url", "promoted_metrics", "public_metrics", "revenue", "type", "url", "variants", "width"]]`

A comma separated list of Media fields to display.

**poll\_fields** `List[Literal["duration_minutes", "end_datetime", "id", "options", "voting_status"]]`

A comma separated list of Poll fields to display.

**place\_fields** `List[Literal["contained_within", "country", "country_code", "full_name", "geo", "id", "name", "place_type"]]`

A comma separated list of Place fields to display.

**Returns:** `GetByIdsResponse`

***

## `get_counts_all`

GET `/2/tweets/counts/all` Paginated

**Get Count of All Posts**

Retrieves the count of Posts matching a search query from the full archive.

At most one of `pagination_token`, `next_token` may be provided.

```python theme={null}
import os
from xdk import Client

client = Client(bearer_token=os.environ["X_BEARER_TOKEN"])

for page in client.posts.get_counts_all(query="from:XDevelopers"):
    print(page.data)
```

### Parameters

**query** `str` *required*

`query` (query parameter).

**Optional keyword arguments (8)**

**start\_time** `str`

`start_time` (query parameter).

**end\_time** `str`

`end_time` (query parameter).

**since\_id** `str`

`since_id` (query parameter).

**until\_id** `str`

`until_id` (query parameter).

**next\_token** `str`

A base32hex-encoded pagination token.

**pagination\_token** `str`

A base32hex-encoded pagination token.

**granularity** `Literal["minute", "hour", "day"]`

`granularity` (query parameter).

**search\_count\_fields** `str`

`search_count.fields` (query parameter).

**Returns:** `Iterator[GetCountsAllResponse]`

***

## `get_counts_recent`

GET `/2/tweets/counts/recent` Paginated

**Get Count of Recent Posts**

Retrieves the count of Posts from the last 7 days matching a search query.

At most one of `pagination_token`, `next_token` may be provided.

```python theme={null}
import os
from xdk import Client

client = Client(bearer_token=os.environ["X_BEARER_TOKEN"])

for page in client.posts.get_counts_recent(query="from:XDevelopers"):
    print(page.data)
```

### Parameters

**query** `str` *required*

`query` (query parameter).

**Optional keyword arguments (8)**

**start\_time** `str`

Must be within the last 7 days.

**end\_time** `str`

`end_time` (query parameter).

**since\_id** `str`

`since_id` (query parameter).

**until\_id** `str`

`until_id` (query parameter).

**next\_token** `str`

A base32hex-encoded pagination token.

**pagination\_token** `str`

A base32hex-encoded pagination token.

**granularity** `Literal["minute", "hour", "day"]`

`granularity` (query parameter).

**search\_count\_fields** `str`

`search_count.fields` (query parameter).

**Returns:** `Iterator[GetCountsRecentResponse]`

***

## `get_liking_users`

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

**Get Liking Users**

Retrieves a list of Users who liked a specific Post by its ID.

```python theme={null}
import os
from xdk import Client

client = Client(access_token=os.environ["X_ACCESS_TOKEN"])

for page in client.posts.get_liking_users(id="1895000000000000000"):
    print(page.data)
```

### Parameters

**id** `schemas.PostId` *required*

`id` (path parameter).

**Optional keyword arguments (5)**

**max\_results** `int`

`max_results` (query parameter).

**pagination\_token** `str`

A base32hex-encoded pagination token.

**user\_fields** `List[Literal["active_follower_count", "confirmed_email", "connection_status", "created_at", "description", "entities", "id", "is_identity_verified", "location", "name", "org_only", "parody", "profile_banner_url", "profile_image_url", "protected", "public_metrics", "receives_your_chat", "receives_your_dm", "subscriber_count", "subscribes_to_you", "subscription", "subscription_type", "url", "username", "verified", "verified_followers_count", "verified_type", "withheld"]]`

A comma separated list of User fields to display.

**expansions** `List[Literal["affiliation", "most_recent_post_id", "pinned_post_id"]]`

A comma separated list of fields to expand.

**post\_fields** `List[Literal["article", "article_title", "attachments", "card_uri", "community_id", "context_annotations", "conversation_id", "created_at", "display_text_range", "edit_controls", "entities", "geo", "id", "lang", "matched_media_notes", "media_metadata", "non_public_metrics", "note_post", "note_request_suggestions", "organic_metrics", "paid_partnership", "possibly_sensitive", "promoted_metrics", "public_metrics", "reply_settings", "scopes", "source", "suggested_source_links", "suggested_source_links_with_counts", "text", "withheld"]]`

A comma separated list of Post fields to display.

**Returns:** `Iterator[GetLikingUsersResponse]`

***

## `get_post_drafts`

GET `/2/posts/drafts` Paginated

**Get Post Drafts**

Returns the authenticated user's Post drafts, newest first, in the fields of the Create or Edit Post body. thread holds the Posts after the first. A draft with unsupported\_content is not listed in full: do not publish it from this list or delete it unless the user asks. Needs the tweet.write scope.

```python theme={null}
import os
from xdk import Client

client = Client(access_token=os.environ["X_ACCESS_TOKEN"])

for page in client.posts.get_post_drafts():
    print(page.data)
```

### Parameters

**Optional keyword arguments (2)**

**max\_results** `int`

The maximum number of drafts to return.

**pagination\_token** `str`

The meta.next\_token of the previous page.

**Returns:** `Iterator[GetPostDraftsResponse]`

***

## `get_quoted`

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

**Get Quoted Posts**

Retrieves a list of Posts that quote a specific Post by its ID.

```python theme={null}
import os
from xdk import Client

client = Client(bearer_token=os.environ["X_BEARER_TOKEN"])

for page in client.posts.get_quoted(id="1895000000000000000"):
    print(page.data)
```

### Parameters

**id** `schemas.PostId` *required*

`id` (path parameter).

**Optional keyword arguments (9)**

**max\_results** `int`

`max_results` (query parameter).

**pagination\_token** `str`

A base32hex-encoded pagination token.

**exclude** `List[Literal["replies", "retweets"]]`

`exclude` (query parameter).

**post\_fields** `List[Literal["article", "article_title", "attachments", "card_uri", "community_id", "context_annotations", "conversation_id", "created_at", "display_text_range", "edit_controls", "entities", "geo", "id", "lang", "matched_media_notes", "media_metadata", "non_public_metrics", "note_post", "note_request_suggestions", "organic_metrics", "paid_partnership", "possibly_sensitive", "promoted_metrics", "public_metrics", "reply_settings", "scopes", "source", "suggested_source_links", "suggested_source_links_with_counts", "text", "withheld"]]`

A comma separated list of Post fields to display.

**expansions** `List[Literal["article.cover_media", "article.media_entities", "attachments.media_keys", "attachments.media_source_tweet", "attachments.poll_ids", "author_id", "edit_history_post_ids", "entities.mentions.username", "geo.place_id", "in_reply_to_user_id", "referenced_posts", "username"]]`

A comma separated list of fields to expand.

**user\_fields** `List[Literal["active_follower_count", "confirmed_email", "connection_status", "created_at", "description", "entities", "id", "is_identity_verified", "location", "name", "org_only", "parody", "profile_banner_url", "profile_image_url", "protected", "public_metrics", "receives_your_chat", "receives_your_dm", "subscriber_count", "subscribes_to_you", "subscription", "subscription_type", "url", "username", "verified", "verified_followers_count", "verified_type", "withheld"]]`

A comma separated list of User fields to display.

**media\_fields** `List[Literal["alt_text", "duration_ms", "height", "media_key", "non_public_metrics", "organic_metrics", "preview_image_url", "promoted_metrics", "public_metrics", "revenue", "type", "url", "variants", "width"]]`

A comma separated list of Media fields to display.

**poll\_fields** `List[Literal["duration_minutes", "end_datetime", "id", "options", "voting_status"]]`

A comma separated list of Poll fields to display.

**place\_fields** `List[Literal["contained_within", "country", "country_code", "full_name", "geo", "id", "name", "place_type"]]`

A comma separated list of Place fields to display.

**Returns:** `Iterator[GetQuotedResponse]`

***

## `get_reposted_by`

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

**Get Reposted By**

Retrieves a list of Users who reposted a specific Post by its ID.

```python theme={null}
import os
from xdk import Client

client = Client(bearer_token=os.environ["X_BEARER_TOKEN"])

for page in client.posts.get_reposted_by(id="1895000000000000000"):
    print(page.data)
```

### Parameters

**id** `schemas.PostId` *required*

`id` (path parameter).

**Optional keyword arguments (5)**

**max\_results** `int`

`max_results` (query parameter).

**pagination\_token** `str`

A base32hex-encoded pagination token.

**user\_fields** `List[Literal["active_follower_count", "confirmed_email", "connection_status", "created_at", "description", "entities", "id", "is_identity_verified", "location", "name", "org_only", "parody", "profile_banner_url", "profile_image_url", "protected", "public_metrics", "receives_your_chat", "receives_your_dm", "subscriber_count", "subscribes_to_you", "subscription", "subscription_type", "url", "username", "verified", "verified_followers_count", "verified_type", "withheld"]]`

A comma separated list of User fields to display.

**expansions** `List[Literal["affiliation", "most_recent_post_id", "pinned_post_id"]]`

A comma separated list of fields to expand.

**post\_fields** `List[Literal["article", "article_title", "attachments", "card_uri", "community_id", "context_annotations", "conversation_id", "created_at", "display_text_range", "edit_controls", "entities", "geo", "id", "lang", "matched_media_notes", "media_metadata", "non_public_metrics", "note_post", "note_request_suggestions", "organic_metrics", "paid_partnership", "possibly_sensitive", "promoted_metrics", "public_metrics", "reply_settings", "scopes", "source", "suggested_source_links", "suggested_source_links_with_counts", "text", "withheld"]]`

A comma separated list of Post fields to display.

**Returns:** `Iterator[GetRepostedByResponse]`

***

## `get_reposts`

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

**Get Reposts**

Retrieves a list of Posts that repost a specific Post by its ID.

```python theme={null}
import os
from xdk import Client

client = Client(bearer_token=os.environ["X_BEARER_TOKEN"])

for page in client.posts.get_reposts(id="1895000000000000000"):
    print(page.data)
```

### Parameters

**id** `schemas.PostId` *required*

`id` (path parameter).

**Optional keyword arguments (8)**

**max\_results** `int`

`max_results` (query parameter).

**pagination\_token** `str`

A base32hex-encoded pagination token.

**post\_fields** `List[Literal["article", "article_title", "attachments", "card_uri", "community_id", "context_annotations", "conversation_id", "created_at", "display_text_range", "edit_controls", "entities", "geo", "id", "lang", "matched_media_notes", "media_metadata", "non_public_metrics", "note_post", "note_request_suggestions", "organic_metrics", "paid_partnership", "possibly_sensitive", "promoted_metrics", "public_metrics", "reply_settings", "scopes", "source", "suggested_source_links", "suggested_source_links_with_counts", "text", "withheld"]]`

A comma separated list of Post fields to display.

**expansions** `List[Literal["article.cover_media", "article.media_entities", "attachments.media_keys", "attachments.media_source_tweet", "attachments.poll_ids", "author_id", "edit_history_post_ids", "entities.mentions.username", "geo.place_id", "in_reply_to_user_id", "referenced_posts", "username"]]`

A comma separated list of fields to expand.

**user\_fields** `List[Literal["active_follower_count", "confirmed_email", "connection_status", "created_at", "description", "entities", "id", "is_identity_verified", "location", "name", "org_only", "parody", "profile_banner_url", "profile_image_url", "protected", "public_metrics", "receives_your_chat", "receives_your_dm", "subscriber_count", "subscribes_to_you", "subscription", "subscription_type", "url", "username", "verified", "verified_followers_count", "verified_type", "withheld"]]`

A comma separated list of User fields to display.

**media\_fields** `List[Literal["alt_text", "duration_ms", "height", "media_key", "non_public_metrics", "organic_metrics", "preview_image_url", "promoted_metrics", "public_metrics", "revenue", "type", "url", "variants", "width"]]`

A comma separated list of Media fields to display.

**poll\_fields** `List[Literal["duration_minutes", "end_datetime", "id", "options", "voting_status"]]`

A comma separated list of Poll fields to display.

**place\_fields** `List[Literal["contained_within", "country", "country_code", "full_name", "geo", "id", "name", "place_type"]]`

A comma separated list of Place fields to display.

**Returns:** `Iterator[GetRepostsResponse]`

***

## `hide_reply`

PUT `/2/tweets/{tweet_id}/hidden`

**Hide Reply**

Hides or unhides a reply to a conversation owned by the authenticated user.

```python theme={null}
import os
from xdk import Client
from xdk.posts.models import HideReplyRequest

client = Client(access_token=os.environ["X_ACCESS_TOKEN"])

response = client.posts.hide_reply(tweet_id="1895000000000000000", body=HideReplyRequest(hidden=True))
print(response)
```

### Parameters

**tweet\_id** `schemas.PostId` *required*

`tweet_id` (path parameter).

**body** `HideReplyRequest` *required*

Request payload.

**Returns:** `HideReplyResponse`

***

## `search_all`

GET `/2/tweets/search/all` Paginated

**Search All Posts**

Retrieves Posts from the full archive matching a search query.

At most one of `start_time`, `since_id` may be provided. At most one of `end_time`, `until_id` may be provided. At most one of `pagination_token`, `next_token` may be provided.

```python theme={null}
import os
from xdk import Client

client = Client(bearer_token=os.environ["X_BEARER_TOKEN"])

for page in client.posts.search_all(query="from:XDevelopers"):
    print(page.data)
```

### Parameters

**query** `str` *required*

`query` (query parameter).

**Optional keyword arguments (14)**

**start\_time** `str`

`start_time` (query parameter).

**end\_time** `str`

`end_time` (query parameter).

**since\_id** `str`

`since_id` (query parameter).

**until\_id** `str`

`until_id` (query parameter).

**max\_results** `int`

`max_results` (query parameter).

**next\_token** `str`

A base32hex-encoded pagination token.

**pagination\_token** `str`

A base32hex-encoded pagination token.

**sort\_order** `Literal["recency", "relevancy"]`

`sort_order` (query parameter).

**post\_fields** `List[Literal["article", "article_title", "attachments", "card_uri", "community_id", "context_annotations", "conversation_id", "created_at", "display_text_range", "edit_controls", "entities", "geo", "id", "lang", "matched_media_notes", "media_metadata", "non_public_metrics", "note_post", "note_request_suggestions", "organic_metrics", "paid_partnership", "possibly_sensitive", "promoted_metrics", "public_metrics", "reply_settings", "scopes", "source", "suggested_source_links", "suggested_source_links_with_counts", "text", "withheld"]]`

A comma separated list of Post fields to display.

**expansions** `List[Literal["article.cover_media", "article.media_entities", "attachments.media_keys", "attachments.media_source_tweet", "attachments.poll_ids", "author_id", "edit_history_post_ids", "entities.mentions.username", "geo.place_id", "in_reply_to_user_id", "referenced_posts", "username"]]`

A comma separated list of fields to expand.

**user\_fields** `List[Literal["active_follower_count", "confirmed_email", "connection_status", "created_at", "description", "entities", "id", "is_identity_verified", "location", "name", "org_only", "parody", "profile_banner_url", "profile_image_url", "protected", "public_metrics", "receives_your_chat", "receives_your_dm", "subscriber_count", "subscribes_to_you", "subscription", "subscription_type", "url", "username", "verified", "verified_followers_count", "verified_type", "withheld"]]`

A comma separated list of User fields to display.

**media\_fields** `List[Literal["alt_text", "duration_ms", "height", "media_key", "non_public_metrics", "organic_metrics", "preview_image_url", "promoted_metrics", "public_metrics", "revenue", "type", "url", "variants", "width"]]`

A comma separated list of Media fields to display.

**poll\_fields** `List[Literal["duration_minutes", "end_datetime", "id", "options", "voting_status"]]`

A comma separated list of Poll fields to display.

**place\_fields** `List[Literal["contained_within", "country", "country_code", "full_name", "geo", "id", "name", "place_type"]]`

A comma separated list of Place fields to display.

**Returns:** `Iterator[SearchAllResponse]`

***

## `search_recent`

GET `/2/tweets/search/recent` Paginated

**Search Recent Posts**

Retrieves Posts from the last 7 days matching a search query.

At most one of `start_time`, `since_id` may be provided. At most one of `end_time`, `until_id` may be provided. At most one of `pagination_token`, `next_token` may be provided.

```python theme={null}
import os
from xdk import Client

client = Client(bearer_token=os.environ["X_BEARER_TOKEN"])

for page in client.posts.search_recent(query="from:XDevelopers"):
    print(page.data)
```

### Parameters

**query** `str` *required*

`query` (query parameter).

**Optional keyword arguments (14)**

**max\_results** `int`

`max_results` (query parameter).

**next\_token** `str`

A base32hex-encoded pagination token.

**pagination\_token** `str`

A base32hex-encoded pagination token.

**start\_time** `str`

Must be within the last 7 days.

**end\_time** `str`

`end_time` (query parameter).

**since\_id** `str`

`since_id` (query parameter).

**until\_id** `str`

`until_id` (query parameter).

**sort\_order** `Literal["recency", "relevancy"]`

`sort_order` (query parameter).

**post\_fields** `List[Literal["article", "article_title", "attachments", "card_uri", "community_id", "context_annotations", "conversation_id", "created_at", "display_text_range", "edit_controls", "entities", "geo", "id", "lang", "matched_media_notes", "media_metadata", "non_public_metrics", "note_post", "note_request_suggestions", "organic_metrics", "paid_partnership", "possibly_sensitive", "promoted_metrics", "public_metrics", "reply_settings", "scopes", "source", "suggested_source_links", "suggested_source_links_with_counts", "text", "withheld"]]`

A comma separated list of Post fields to display.

**expansions** `List[Literal["article.cover_media", "article.media_entities", "attachments.media_keys", "attachments.media_source_tweet", "attachments.poll_ids", "author_id", "edit_history_post_ids", "entities.mentions.username", "geo.place_id", "in_reply_to_user_id", "referenced_posts", "username"]]`

A comma separated list of fields to expand.

**user\_fields** `List[Literal["active_follower_count", "confirmed_email", "connection_status", "created_at", "description", "entities", "id", "is_identity_verified", "location", "name", "org_only", "parody", "profile_banner_url", "profile_image_url", "protected", "public_metrics", "receives_your_chat", "receives_your_dm", "subscriber_count", "subscribes_to_you", "subscription", "subscription_type", "url", "username", "verified", "verified_followers_count", "verified_type", "withheld"]]`

A comma separated list of User fields to display.

**media\_fields** `List[Literal["alt_text", "duration_ms", "height", "media_key", "non_public_metrics", "organic_metrics", "preview_image_url", "promoted_metrics", "public_metrics", "revenue", "type", "url", "variants", "width"]]`

A comma separated list of Media fields to display.

**poll\_fields** `List[Literal["duration_minutes", "end_datetime", "id", "options", "voting_status"]]`

A comma separated list of Poll fields to display.

**place\_fields** `List[Literal["contained_within", "country", "country_code", "full_name", "geo", "id", "name", "place_type"]]`

A comma separated list of Place fields to display.

**Returns:** `Iterator[SearchRecentResponse]`

***
