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

# X (Twitter) Scraper API 端点

> 使用可复制粘贴的代码示例向Bright Data X爬虫API端点发起同步请求。

本指南介绍如何向每个 Bright Data X Scraper API 端点发送同步请求。完成后，您将拥有用于配置文件和帖子的工作示例。

## 前提条件

* 具有活跃 API 密钥的 [Bright Data 账户](https://www.bright.cn/products/web-scraper/twitter?hs_signup=1\&utm_source=docs)
* 已完成 [快速入门](/cn/products/scrapers/twitter/quickstart)

## 请求结构

每个同步请求都遵循相同的模式：

```
POST https://api.brightdata.com/datasets/v3/scrape?dataset_id={DATASET_ID}&format=json
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

[{"url": "https://x.com/..."}]
```

端点之间唯一变化的是 `dataset_id` 和输入 URL 格式。

<Note>
  `/scrape` 端点专为实时的单 URL 请求设计。Bright Data 建议每个请求不超过 20 个 URL（这是最佳实践，而非硬性限制），端点最多等待 1 分钟。如果采集耗时更长，响应为 HTTP `202`，返回 `snapshot_id` 而不是数据，采集将继续以异步方式进行。请通过[异步请求](/cn/products/scrapers/scrapers-library/async-requests)获取结果，或使用 [Webhook 投递](/cn/products/scrapers/scrapers-library/data-delivery)接收结果。
</Note>

## 配置文件

**数据集 ID：** `gd_lwxmeb2u1cniijd7t4`

```bash theme={null}
curl -X POST \
  "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_lwxmeb2u1cniijd7t4&format=json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{"url": "https://x.com/elonmusk"}]'
```

您应该会看到 `200` 响应。处理时间取决于目标网站状况和爬虫负载。

<Accordion title="示例响应">
  ```json theme={null}
  [
    {
      "followers": 241583960,
      "following": 1403,
      "is_verified": true,
      "profile_image_link": "https://pbs.twimg.com/profile_images/2053244804520427520/m8mdWZCG_400x400.jpg",
      "x_id": "44196397",
      "url": "https://x.com/elonmusk",
      "id": "elonmusk",
      "profile_name": "Elon Musk",
      "biography": "https://t.co/ZdBx5WABYx",
      "date_joined": "2009-06-02T20:12:29.000Z"
    }
  ]
  ```
</Accordion>

[完整配置文件响应架构](/cn/api-reference/scrapers/social-media-apis/twitter-profiles-collect-by-url)

### X (Twitter) 个人资料抓取器返回哪些输出字段？

X (Twitter) 个人资料抓取器（`gd_lwxmeb2u1cniijd7t4`，`collect_by_url`）返回 22 个输出字段。字段说明保留 API 返回的英文原文。

<Accordion title="输出字段（22）">
  | 字段 | 类型 | 说明 |
  | - | - | - |
  | `x_id` | text | Unique X id of each profile |
  | `url` | url | Profile URL |
  | `id` | text | ID of the post |
  | `profile_name` | text | Profile username |
  | `biography` | text | Bio of the profile |
  | `is_verified` | boolean | Is the user verified |
  | `profile_image_link` | url | Profile Image link |
  | `external_link` | url | External link |
  | `date_joined` | date | Date where the profile joined twitter |
  | `following` | number | Number of profiles the user follows |
  | `followers` | number | Number of followers of the profile |
  | `subscriptions` | number | Number of subscriptions of the profile |
  | `location` | text | Profile location |
  | `birth_date` | date | Profile birth date |
  | `posts_count` | number | Number of profile's posts |
  | `posts` | array | |
  | `suggested_profiles` | array | Suggested profiles |
  | `is_business_account` | boolean | Is the profile a business account |
  | `is_government_account` | boolean | Is it a government account |
  | `category_name` | array | Category names |
  | `max_number_of_posts` | number | The number of posts input from discovery |
  | `banner_image` | url | The profile's banner image |
</Accordion>

包含输入 schema 的机器可读版本：[`/scrapers/gd_lwxmeb2u1cniijd7t4.json`](/scrapers/gd_lwxmeb2u1cniijd7t4.json)

## 帖子

**数据集 ID：** `gd_lwxkxvnf1cynvib9co`

```bash theme={null}
curl -X POST \
  "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_lwxkxvnf1cynvib9co&format=json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{"url": "https://x.com/elonmusk/status/1519480761749016577"}]'
```

<Accordion title="示例响应">
  ```json theme={null}
  [
    {
      "url": "https://x.com/elonmusk/status/1519480761749016577",
      "user_posted": "elonmusk",
      "description": "Next I’m buying Coca-Cola to put the cocaine back in",
      "date_posted": "2022-04-28T00:56:58.000Z",
      "likes": 4196406,
      "replies": 167707,
      "hashtags": null,
      "id": "1519480761749016577",
      "name": "Elon Musk",
      "reposts": 577446
    }
  ]
  ```
</Accordion>

[完整帖子响应架构](/cn/api-reference/scrapers/social-media-apis/twitter-posts-collect-by-url)

### X (Twitter) 帖子抓取器返回哪些输出字段？

X (Twitter) 帖子抓取器（`gd_lwxkxvnf1cynvib9co`，`collect_by_url`）返回 32 个输出字段。字段说明保留 API 返回的英文原文。

<Accordion title="输出字段（32）">
  | 字段 | 类型 | 说明 |
  | - | - | - |
  | `id` | text | ID of the post |
  | `user_posted` | text | Username of the post owner |
  | `name` | text | Name of the post owner |
  | `description` | text | Post text description |
  | `date_posted` | date | Post publication date |
  | `photos` | array | URLs of attached photos |
  | `url` | url | URL of the post |
  | `quoted_post` | object | Quoted post details |
  | `tagged_users` | array | Tagged profiles from the post |
  | `replies` | number | Number of replies |
  | `reposts` | number | Number of reposts; There may be a difference between the value displayed on the web interface and the actual value collected from the server side, where the data is retrieved |
  | `likes` | number | Number of likes |
  | `views` | number | Number of views |
  | `external_url` | url | External URL from a post |
  | `hashtags` | array | Hashtags from the post |
  | `followers` | number | Number of followers of the profile |
  | `biography` | text | Bio of the profile |
  | `posts_count` | number | Number of profile's posts |
  | `profile_image_link` | url | Profile image link |
  | `following` | number | Number of profiles the user follows |
  | `is_verified` | boolean | Is the user verified |
  | `quotes` | number | Number of times the post was quoted |
  | `bookmarks` | number | The number of times the post was bookmarked |
  | `parent_post_details` | object | Details of the parent post this post is replying to |
  | `external_image_urls` | array | The URL for the images attached to the post |
  | `videos` | array | Videos attached to the post |
  | `external_video_urls` | array | URLs of externally hosted videos attached to the post |
  | `verification_type` | text | The type of verification badge assigned to the user's profile (e.g. blue check, organization) |
  | `user_id` | text | The user ID |
  | `context_added` | text | Context added by the readers |
  | `is_repost` | boolean | True when the post is a repost |
  | `ai_generated_images` | array | List of images attached to the post, each with its URL and AI generation label |
</Accordion>

包含输入 schema 的机器可读版本：[`/scrapers/gd_lwxkxvnf1cynvib9co.json`](/scrapers/gd_lwxkxvnf1cynvib9co.json)

## 快速参考：数据集 ID

| 端点 | 数据集 ID | URL 模式 |
| :- | :- | :- |
| 配置文件 | `gd_lwxmeb2u1cniijd7t4` | `x.com/{username}` |
| 帖子 | `gd_lwxkxvnf1cynvib9co` | `x.com/{username}/status/{id}` |

## 输出格式

使用 `format` 查询参数控制响应格式：

| 值 | 描述 |
| :- | :- |
| `json` | JSON 数组 |
| `ndjson` | 换行符分隔的 JSON，每行一条记录（默认） |
| `csv` | 逗号分隔值 |

以上是 `/scrape` 的 `format` 值。完整列表（NDJSON（默认）、JSON、JSON lines、CSV 和 Parquet）及各格式适用范围见[输出格式](/cn/products/scrapers/scrapers-library/data-delivery#支持哪些输出格式)。

## 相关内容

<CardGroup cols={2}>
  <Card title="异步批量请求" icon="layer-group" href="/products/scrapers/scrapers-library/async-requests">
    在单个批处理作业中抓取数百个 URL。
  </Card>

  <Card title="API 参考" icon="code" href="/api-reference/scrapers/social-media-apis/twitter-profiles-collect-by-url">
    完整的参数和响应字段参考。
  </Card>
</CardGroup>
