---
title: "搜索帖子"
canonical_url: "https://tweetstream.io/zh-cn/docs/api/search-posts"
last_updated: 2026-11-05
---

# 搜索帖子

返回与 X 搜索语句匹配的近期 X 帖子，按 X 的“最新”顺序排列（不严格按 ID），并附带下一页的 URL。一次搜索的所有分页合计最多返回 100 条帖子；返回第 100 条后，next 为 null。

Canonical URL: https://tweetstream.io/zh-cn/docs/api/search-posts

## `GET /api/search/posts`

`https://api.tweetstream.io/api/search/posts`

## 授权

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `Authorization` | `string`, 必填 | 使用 TweetStream API 密钥进行 Bearer 认证：`Bearer <key>`。 |

## 查询参数

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `query` | `string`, 必填 | X 搜索语句，可包含搜索运算符。 |
| `limit` | `integer` | 最多返回的帖子数。 |
| `page` | `string` | 不透明值，只能取自 next。 |

## 响应字段

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `next` | `string \| null`, 必填 | Absolute URL of the next page: request it as it is, with the same API key. Null when there is nothing more or the search has returned 100 posts. Works for 30 minutes. |
| `posts` | `object[]`, 必填 |  |
| `posts.kind` | `enum<string>` |  |
| `posts.quoted` | `object` | The post a reply also quotes. A quote keeps the post it quotes in ref and has no quoted. |
| `posts.quoted.type` | `string`, 必填 |  |
| `posts.ref` | `object` |  |
| `posts.ref.type` | `enum<string>`, 必填 |  |
| `posts.metrics` | `object`, 必填 |  |
| `posts.metrics.bookmarks` | `integer`, 必填 |  |
| `posts.metrics.likes` | `integer`, 必填 |  |
| `posts.metrics.quotes` | `integer`, 必填 |  |
| `posts.metrics.replies` | `integer`, 必填 |  |
| `posts.metrics.reposts` | `integer`, 必填 |  |
| `posts.metrics.views` | `integer \| null`, 必填 |  |
| `posts.tweetId` | `string`, 必填 |  |

## 响应

| 状态 | 说明 | 请求头 |
| --- | --- | --- |
| `200` | 成功 |  |
| `400` | query 或 limit 无效，或分页链接被修改或已超过 30 分钟。请不带 page 重新搜索。 |  |
| `401` | API key 缺失或无效 |  |
| `403` | 该 API key 所属账号当前没有 Pro、Ultra Speed 或 Scale 订阅。 |  |
| `405` | 只支持 GET |  |
| `429` | 账号的搜索额度已用完，或进行中的搜索已达套餐上限：Pro 每分钟 60 次（突发 10 次，同时进行 4 个）；Ultra Speed 每分钟 120 次（突发 10 次，同时进行 6 个）；Scale 每分钟 300 次（突发 10 次，同时进行 10 个） | `Retry-After` |
| `503` | 帖子搜索或认证暂时不可用 | `Retry-After` |

### 200

```json
{
  "posts": [
    {
      "tweetId": "2118183412095201280",
      "text": "Solana validators shipped the new client today.",
      "createdAt": 1793849254045,
      "kind": "post",
      "link": "https://x.com/marketdesk/status/2118183412095201280",
      "author": {
        "id": "1189745302",
        "handle": "@marketdesk",
        "name": "Market Desk",
        "platform": "twitter",
        "verifiedType": "blue",
        "followersCount": 48210,
        "followingCount": 312,
        "profileImage": "https://pbs.twimg.com/profile_images/marketdesk_400x400.jpg"
      },
      "metrics": {
        "likes": 1204,
        "replies": 87,
        "reposts": 230,
        "quotes": 19,
        "bookmarks": 41,
        "views": null
      }
    }
  ],
  "next": "https://api.tweetstream.io/api/search/posts?limit=1&page=AZx3q0Vh1mR2k9Q&query=solana+lang%3Aen+-is%3Aretweet"
}
```

### 400

```json
{
  "error": "<string>"
}
```

### 401

```json
{
  "error": "<string>"
}
```

### 403

```json
{
  "error": "<string>"
}
```

### 429

```json
{
  "error": "<string>",
  "retryAfterSeconds": 0
}
```

### 503

```json
{
  "error": "<string>"
}
```

## 代码示例

### cURL

```bash
curl --request GET \
  --url 'https://api.tweetstream.io/api/search/posts?query=solana+lang%3Aen+-is%3Aretweet' \
  --header "Authorization: Bearer $TWEETSTREAM_API_KEY"
```

### JavaScript

```javascript
const response = await fetch("https://api.tweetstream.io/api/search/posts?query=solana+lang%3Aen+-is%3Aretweet", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${process.env.TWEETSTREAM_API_KEY}`,
  },
});

console.log(response.status, await response.json());
```

### Python

```python
import os
import requests

response = requests.get(
    "https://api.tweetstream.io/api/search/posts",
    headers={"Authorization": f"Bearer {os.environ['TWEETSTREAM_API_KEY']}"},
    params=[("query", "solana lang:en -is:retweet")],
)

print(response.status_code, response.json())
```
