Python SDK
使用 TwexAPI Python SDK 在同步或异步任务中进行推文搜索、粉丝导出、私信与 X API 自动化。
当你需要在脚本、worker 与AI Agent后端中获得类型化请求对象、响应模型、重试与分页辅助的 TwexAPI REST 工作流时,请使用 Python SDK。
| Python 任务 | SDK 调用 | 保存 |
|---|---|---|
| 搜索推文 | client.search.advanced |
next_cursor |
| 读取资料 | client.users.get_about |
screen_name |
| 列出粉丝 | client.users.followers.list |
cursor |
错误处理
from x_api_scraper.models.errors import XAPIScraperError
try:
client.search.advanced(
search_terms=["from:elonmusk"],
sort_by="Latest",
next_cursor="",
)
except XAPIScraperError as error:
print(error.status_code, error.body)
使用 X_API_SCRAPER_DEBUG=true 启用调试日志。