This example fetches replies to one public X post. You pass the post id and how many replies to return.
It is a single post's reply list. The reply ledger example is different: that one reads the replies an account itself has posted.
The problem
The replies under one post are the conversation about that post. Copying them out means scrolling, and a keyword in the reply text is easy to miss once the list is long.
What the app does
- Takes a post id and a count.
- Returns the replies Desearch sent back for that post.
- Prints the result. Each reply can include text, counts, time and a URL.
How it works
The file calls x_post_replies with post_id and count. It calls GET /twitter/replies/post. The comment in the file also lists query on the method. This call does not pass query. It returns up to count replies; older posts may return fewer.
The code
import asyncio
import os
from desearch_py import Desearch
# Set DESEARCH_API_KEY in your environment to a key from the Desearch console. Do not commit a real key.
API_KEY = os.environ["DESEARCH_API_KEY"]
async def main():
# desearch-py 1.2.1: x_post_replies(post_id, count, query)
# calls GET /twitter/replies/post. Replace the sample post id with a public id.
async with Desearch(api_key=API_KEY) as desearch:
result = await desearch.x_post_replies(
post_id="1276418907968925696",
count=10,
)
print(result)
if __name__ == "__main__":
asyncio.run(main())Set DESEARCH_API_KEY in your environment to your API key. Do not commit a real key. Replace the sample post id with a real public id.
Endpoints
GET /twitter/replies/post
Example output
The script prints the response. The file does not include a saved sample run or a measured cost.
Run it yourself
The file linked above is twitter_replies_post.py in the examples repository. Install desearch-py 1.2.1, create a key at console.desearch.ai, and call x_post_replies with a post id and a count.
What it costs
This example does not record X-Desearch-Cost-Usd. Current responses include that header. See pricing.
Ideas to extend it
- Write the replies to a CSV with the post id on every row.
- Sort the returned replies by like count.
- Pair this with the quote ledger when a launch post has both quotes and replies.
