X/Twitter API 文档

X/Twitter API: 搜索 — 按查询获取帖子

根据用户查询在 X/Twitter 上发现搜索数据,并将结果接入搜索、目录或研究界面。

当不知道确切的对象 ID、需要先找到相关候选项时,请使用“按查询获取帖子”。

方法 GET
实体 搜索
版本 2
此端点的作用

利用此 API 方法可以构建什么

先查看结果和常见工作流,然后再了解参数和可运行的请求示例。

此端点可以帮助您

响应包含匹配的搜索、公开上下文,以及在有更多结果时的分页数据。

何时使用

当不知道确切的对象 ID、需要先找到相关候选项时,请使用“按查询获取帖子”。

常见使用场景

产品内搜索

在面向客户的界面和内部界面中加入 X/Twitter 数据搜索。

构建目录

按查询查找候选项,并保存相关对象以供后续补全。

市场研究

收集结果集,用于主题、创作者和竞品分析。

可用版本

响应版本

两个版本完成相同的任务,接受相同的参数。使用切换按钮比较响应结构,并选择您的客户端所需的版本。

响应版本 V2

在本页面切换版本,即可在同一文档 URL 下比较响应结构。

保持不变的部分

V1 和 V2 的身份验证、必填参数和请求结构均相同。实际上,您只需在构建端点路径和解析响应时选择版本。

版本之间的差异

主要区别在于响应结构。新集成请使用 V2;仅在需要兼容现有客户端契约时保留 V1。

使用方法

如何调用该方法

两个版本使用相同的 API 密钥请求头和相同的查询参数。本文档先展示共享的参数集合,然后展示各版本特定的端点路径和代码片段。

输入参数

共享参数
参数 必填 类型 示例 说明
query 是 str technology 用户输入的搜索关键词。
all_of_these_words 否 str | None AI robotics Optional words that must all appear in matching Twitter/X posts. Example: AI robotics.
any_of_these_words 否 str | None launch release Optional words where any one may appear in matching Twitter/X posts. Example: launch release.
cursor 否 str | None DAABCgABF4ABCD... 上一次响应返回的下一页游标。获取第一页时请省略。
exact_phrase 否 str | None machine learning Optional exact phrase that must appear in matching Twitter/X posts. Example: machine learning.
from_accounts 否 str | None technews xai Optional source accounts without or with @, separated by spaces or commas. Example: technews xai.
hashtags 否 str | None #TechNews #AI Optional hashtags to require, separated by spaces or commas. Example: #TechNews #AI.
language 否 str | None en Optional Twitter/X language code. Use 'any' to omit language filtering. Example: en.
link_filter 否 include | only | exclude | None only Optional link filter: include all posts, only posts with links, or exclude links. Example: only.
mentioning_accounts 否 str | None technews elonmusk Optional mentioned accounts without or with @, separated by spaces or commas. Example: technews elonmusk.
min_likes 否 int | None 100 Optional minimum like count. Example: 100.
min_replies 否 int | None 10 Optional minimum reply count. Example: 10.
min_retweets 否 int | None 25 Optional minimum repost/retweet count. Example: 25.
none_of_these_words 否 str | None rumor leak Optional words to exclude from matching Twitter/X posts. Example: rumor leak.
reply_filter 否 include | only | exclude | None exclude Optional reply filter: include all posts, only replies, or exclude replies. Example: exclude.
since_date 否 date | None 2026-01-01 Optional earliest post date in ISO YYYY-MM-DD format. Example: 2026-01-01.
tag 否 Top | Latest | People | Photos | Videos | None Latest Optional Twitter/X search product filter. Example: Latest.
to_accounts 否 str | None technews Optional reply target accounts without or with @, separated by spaces or commas. Example: technews.
until_date 否 date | None 2026-01-31 Optional latest post date in ISO YYYY-MM-DD format. Example: 2026-01-31.

各版本的请求路径

V2

复制确切的端点路径、示例 URL 和代码片段时请选择版本。上方的参数列表保持不变。

GET /api/v2/twitter.com/search/tweets-by-query

规范化格式

代码示例

curl --request GET \
  --url "https://www.scrapestorm.net/api/v2/twitter.com/search/tweets-by-query" \
  --header "X-API-Key: 00000000-0000-4000-8000-000000000000" \
  --get --data-urlencode 'query=technology' \
  # Optional parameters:
  # --data-urlencode 'all_of_these_words=AI robotics'
  # --data-urlencode 'any_of_these_words=launch release'
  # --data-urlencode 'cursor=DAABCgABF4ABCD...'
  # --data-urlencode 'exact_phrase=machine learning'
  # --data-urlencode 'from_accounts=technews xai'
  # --data-urlencode 'hashtags=#TechNews #AI'
  # --data-urlencode 'language=en'
  # --data-urlencode 'link_filter=only'
  # --data-urlencode 'mentioning_accounts=technews elonmusk'
  # --data-urlencode 'min_likes=100'
  # --data-urlencode 'min_replies=10'
  # --data-urlencode 'min_retweets=25'
  # --data-urlencode 'none_of_these_words=rumor leak'
  # --data-urlencode 'reply_filter=exclude'
  # --data-urlencode 'since_date=2026-01-01'
  # --data-urlencode 'tag=Latest'
  # --data-urlencode 'to_accounts=technews'
  # --data-urlencode 'until_date=2026-01-31'
响应示例

按版本查看真实响应

预览保留了关键字段和集合中的前几项,便于您快速浏览响应结构。切换版本会改变 JSON 格式。

响应示例

V2 响应 JSON

已验证示例

此简明 JSON 示例来自 V2 最近一次成功的验证运行。

{
  "success": true,
  "status": "ok",
  "pagination": {
    "cursor": "QVFB...",
    "has_more": true
  },
  "search_context": {
    "query": "Python code",
    "tag": "Top"
  },
  "data": {
    "tweets": {
      "count": 20,
      "items": [
        {
          "url": "https://x.com/freeCodeCamp/status/2078389573567050090",
          "tweet_id": "2078389573567050090",
          "text": "Learning to code can feel overwhelming when you don't know where to start.\n\nSo here's a course for you: Sunny teaches you Python from the ground up.\n\nYou'll install Python, writ…",
          "hashtags": [],
          "emails": [],
          "created_at": "2026-07-18T08:01:03Z",
          "language": "en",
          "source": "Buffer",
          "author": {
            "url": "https://x.com/freeCodeCamp",
            "user_id": "1668100142",
            "username": "freeCodeCamp",
            "display_name": "freeCodeCamp.org",
            "description": "We're a community of millions of people who are building new skills and getting new jobs together. A 501(c)(3) public charity. Tweets by @abbeyrenn.",
            "emails": [],
            "external_links": [],
            "location": "Just here on Earth... for now",
            "created_at": "2013-08-13T15:27:51Z",
            "is_verified": false,
            "is_blue_verified": true,
            "is_protected": false,
            "possibly_sensitive": false,
            "default_profile": false,
            "default_profile_image": false,
            "followers_count": 1204998,
            "following_count": 159,
            "tweet_count": 36772,
            "media_count": 5153,
            "listed_count": 6833,
            "like_count": 72305,
            "professional_type": null,
            "professional_category_name": null,
            "affiliated_account": null,
            "_more_fields": "5 more fields"
          },
          "is_from_automated_account": null,
          "media": {
            "images": [
              "…"
            ],
            "videos": [],
            "gifs": []
          },
          "external_links": [],
          "user_mentions": [],
          "is_reply": false,
          "reply": null,
          "is_quote": false,
          "quote_tweet_id": null,
          "is_retweet": false,
          "retweeted_tweet_id": null,
          "reply_count": 4,
          "retweet_count": 108,
          "quote_count": 3,
          "like_count": 599,
          "bookmark_count": 455,
          "_more_fields": "2 more fields"
        },
        {
          "url": "https://x.com/PythonPr/status/2078910492068786514",
          "tweet_id": "2078910492068786514",
          "text": "Pyramids in Python Code Examples for Beginners ⭐ https://t.co/QngwbiMVkb",
          "hashtags": [],
          "emails": [],
          "created_at": "2026-07-19T18:31:00Z",
          "language": "en",
          "source": "Twitter Web App",
          "author": {
            "url": "https://x.com/PythonPr",
            "user_id": "855384627975831553",
            "username": "PythonPr",
            "display_name": "Python Programming",
            "description": "#python #programming",
            "emails": [],
            "external_links": [],
            "location": "United States",
            "created_at": "2017-04-21T11:36:02Z",
            "is_verified": false,
            "is_blue_verified": true,
            "is_protected": false,
            "possibly_sensitive": false,
            "default_profile": true,
            "default_profile_image": false,
            "followers_count": 208924,
            "following_count": 1162,
            "tweet_count": 9883,
            "media_count": 4108,
            "listed_count": 1243,
            "like_count": 20597,
            "professional_type": null,
            "professional_category_name": null,
            "affiliated_account": null,
            "_more_fields": "5 more fields"
          },
          "is_from_automated_account": null,
          "media": {
            "images": [
              "…"
            ],
            "videos": [],
            "gifs": []
          },
          "external_links": [],
          "user_mentions": [],
          "is_reply": false,
          "reply": null,
          "is_quote": false,
          "quote_tweet_id": null,
          "is_retweet": false,
          "retweeted_tweet_id": null,
          "reply_count": 3,
          "retweet_count": 8,
          "quote_count": 0,
          "like_count": 62,
          "bookmark_count": 39,
          "_more_fields": "2 more fields"
        },
        {
          "_more_items": 18
        }
      ]
    }
  }
}
下一步

继续评估

将本文档作为第一个决策点,然后在将端点接入常规使用之前,继续了解价格、平台覆盖范围和集成规则。

打开 X/Twitter 平台页面

在实现之前,比较相邻的实体、API 方法分组和相关文档。

打开平台页面

比较 API 方法价格

在扩大使用规模之前,查看此 API 方法在公开价格表中的位置。

查看价格

查看集成规则

通过入门文档确认身份验证、版本管理、重试以及模拟环境与正式环境的差异。

打开文档
常见问题

团队在实现前常问的问题

借助这些解答,判断此 API 方法是否适合您的工作流、版本选择和上线计划。

此 X/Twitter API 方法返回哪些数据?

该方法针对搜索执行“按查询获取帖子”操作。下方的简明响应示例展示了确切的字段结构。

应该选择 V1 还是 V2?

新集成请选择 V2,因为它提供规范化的结构。仅在兼容已使用平台原生格式的客户端时使用 V1。

第一个请求需要准备什么?

创建 API 密钥,在请求头中发送它,并提供表格中的必填参数。代码示例中已包含正确的路径和请求结构。