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

# X API

> 以 JSON 读取公开的 X 推文或个人主页，包括最新推文、点赞、转发、引用、回复、书签、浏览量和发布时间。

通过 `POST /v1/social/x/{action}` 以 JSON 读取公开的 X 数据。用 `{action}` 选择要读取的内容。每次完成的请求消耗 **0.5 积分**。

## 请求

```bash theme={"theme":"css-variables"}
curl -X POST https://api.querying.ai/v1/social/x/profile \
  -H "Authorization: Bearer $QUERYING_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "username": "NASA", "limit": 1 }'
```

请求最多等待结果 290 秒，并以 `200` 应答，结果在 `response` 中。仍在运行的任务以 `202` 应答，请轮询 `GET /v1/async/task/{id}` 或设置 `webhook`；参见[异步任务](https://docs.querying.ai/zh/concepts/async-tasks.md)。

## 操作

| 路径 | 读取内容 | 必填 |
| - | - | - |
| `/v1/social/x/tweet` | 一条推文 | `tweetId` |
| `/v1/social/x/profile` | 公开的个人主页及其最近的推文，约 5 条 | `username` |

`tweetId` 接受推文 ID 或推文 URL，例如 `https://x.com/NASA/status/1585341984679469056`。`postUrl` 和 `url` 接受相同的值。`username` 接受用户名、`@username` 或个人主页 URL，`url` 也接受个人主页 URL。

## 参数

请求中如有其他操作的参数、下列以外的值或缺少必填字段，会在提交时被拒绝，并返回指明该字段的 `400 VALIDATION_ERROR`。

`profile`：

* `limit`：可选，1 到 20 的整数，默认 20，即最多返回的推文数。X 显示个人主页最新的约 5 条推文，因此个人主页返回这么多。

## 响应示例

```json theme={"theme":"css-variables"}
{
  "platform": "x",
  "action": "profile",
  "bio": "Making the seemingly impossible, possible. ✨",
  "url": "https://x.com/NASA",
  "tweets": [
    {
      "url": "https://x.com/NASA/status/2123820070803542306",
      "lang": "en",
      "text": "LIVE: Watch as an uncrewed SpaceX Dragon spacecraft undocks from the @space_station and begins its journey to bring research samples and hardware back to Earth. https://x.com/i/broadcasts/2evOEzWEYBkWyn",
      "links": ["https://x.com/i/broadcasts/2evOEzWEYBkWyn"],
      "media": [],
      "author": {
        "id": "11348282",
        "handle": "NASA",
        "verified": true,
        "displayName": "NASA",
        "verifiedType": "Government",
        "followerCount": 92143728
      },
      "pinned": false,
      "tweetId": "2123820070803542306",
      "hashtags": [],
      "mentions": ["Space_Station"],
      "createdAt": "2026-11-20T16:45:38.000Z",
      "likeCount": 2518,
      "viewCount": 960912,
      "quoteCount": 26,
      "replyCount": 163,
      "retweetCount": 383,
      "bookmarkCount": 101
    }
  ],
  "userId": "11348282",
  "website": "http://www.nasa.gov/",
  "location": "Pale Blue Dot",
  "username": "NASA",
  "verified": true,
  "createdAt": "2007-12-19T20:20:32.000Z",
  "protected": false,
  "mediaCount": 28260,
  "tweetCount": 74572,
  "displayName": "NASA",
  "verifiedType": "Government",
  "followerCount": 92143728,
  "returnedCount": 1,
  "followingCount": 115
}
```

## 结果字段

* 每个响应都会原样返回 `platform` 和 `action`。`profile` 带有 `returnedCount`。
* 推文包含 `tweetId`、`url`、`text`、`lang`、`createdAt`、`author`（`id`、`handle`、`displayName`、`verified`、`verifiedType`、`avatarUrl`、`followerCount`）、`hashtags`、`mentions`、`links`、`media`、`likeCount`、`retweetCount`、`quoteCount`、`replyCount` 和 `bookmarkCount`。
  * `text` 是长推文的完整文本，短链接已展开为原始地址。
  * `media` 列出每项的 `type`，以及 `url`、`previewUrl`、`width`、`height`、视频的 `durationMs` 和设置了时的 `altText`。视频的 `url` 是画质最高的文件。
  * `viewCount` 在 X 显示时出现。回复会增加 `inReplyTo`，包含它所回复的 `handle` 和 `tweetId`；引用会增加 `quotedTweet`。
* `tweet` 返回 `tweet`。
* `profile` 返回 `userId`、`username`、`displayName`、`url`、`bio`、`location`、`website`、`avatarUrl`、`bannerUrl`、`verified`、`verifiedType`、`protected`、`createdAt`、`followerCount`、`followingCount`、`tweetCount`、`mediaCount` 和 `tweets`。`tweets` 中的每条推文都带有 `pinned`，个人主页置顶的推文为 `true`。
* 不存在的推文或账号、已删除的推文，以及受保护或已停用的账号，会使任务以 `PAGE_UNAVAILABLE` 结束。只对完成的请求计费。

## HTML 页面

将 `include.html` 设为 `true`，结果会增加 `html`，即回答所读取的 X 页面的链接，页面保存为可放进报告的文件。`html` 包含 `status`、`url` 和 `expiresAt`，说明见 [HTML 页面](https://docs.querying.ai/zh/engines/html-pages.md)。

* `include.html` 适用于 `tweet` 和 `profile`。
* 文件是 X 为该页面发送的 HTML 文档，即脚本运行之前的状态。文件以一条备注注释开头，`Saved by querying.ai: the page X served for task <id> at <UTC time>, the page as X sent it, before any script ran, the address of the visit and its session ids masked.`
* 属于本次访问的值会替换为等长的零：Cookie 值、会话、请求和设备 ID、CSRF 及其他令牌、nonce，以及媒体地址中的签名。由于这些签名已被遮蔽，文件中的图片和视频链接无法加载。取决于访问来源的内容，例如媒体地址中的区域 CDN 主机名，保持 X 发送时的样子。
* 文档的脚本以文本形式保留在文件中。提供该文件时会附带 Content-Security-Policy，不运行任何脚本，也不加载任何外部资源。
* X 将主要内容以标记形式发送，因此打开的文件可以阅读。
* `tweet` 保留 `x.com/<user>/status/<id>` 页面，`profile` 保留 `x.com/<user>`。
* 页面不额外收费，请求仍为 0.5 积分。
* 无法保存页面时，仍会返回回答，`html` 为 `{ "status": "failed", "error": "EVIDENCE_FAILED" }`。重新提交任务即可再次尝试。

## 相关

* [Threads](https://docs.querying.ai/zh/engines/threads.md)
* [Instagram](https://docs.querying.ai/zh/engines/instagram.md)
* [引擎概览](https://docs.querying.ai/zh/engines/overview.md)
* [积分与限制](https://docs.querying.ai/zh/concepts/credits-and-limits.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.