> ## 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.

# 发送您的第一个Facebook API请求

> 使用可复制粘贴的代码示例向Bright Data Facebook网页抓取器API端点发起同步请求，用于获取资料、页面帖子、帖子、市场和评论。

本指南介绍如何向每个 Bright Data Facebook Scraper API 端点发送同步请求。完成后，你将拥有用于个人资料、页面帖子、帖子、市场列表和评论的工作示例。

## 前提条件

* 一个 [Bright Data 账户](https://www.bright.cn/cp/start) 配有有效的 API key
* 已完成 [快速入门](/cn/products/scrapers/facebook/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://www.facebook.com/..."}]
```

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

<Note>
  同步请求最多支持 20 个 URL，超时时间为 1 分钟。如果请求耗时较长，API 会自动返回 `snapshot_id`。请参阅 [异步请求](/cn/products/scrapers/scrapers-library/async-requests)。
</Note>

## 个人资料

**数据集 ID：** `gd_mf0urb782734ik94dz`

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

你应该会看到 `200` 响应。这需要 10-30 秒。

<Accordion title="示例响应">
  ```json theme={null}
  [
    {
      "name": "Mark Zuckerberg",
      "url": "https://www.facebook.com/zuck",
      "followers": 120000000,
      "bio": "Building the future...",
      "profile_type": "public_figure",
      "is_verified": true
    }
  ]
  ```
</Accordion>

[完整个人资料响应模式](/cn/api-reference/scrapers/social-media-apis/facebook-profiles-collect-by-url)

## 页面帖子

**数据集 ID：** `gd_lkaxegm826bjpoo9m5`

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

<Accordion title="示例响应">
  ```json theme={null}
  [
    {
      "url": "https://www.facebook.com/NASA",
      "post_text": "Exploring the cosmos...",
      "num_comments": 450,
      "date_posted": "2024-04-10T14:30:00.000Z",
      "reactions": 12500,
      "content_type": "Photo"
    }
  ]
  ```
</Accordion>

[完整页面帖子响应模式](/cn/api-reference/scrapers/social-media-apis/facebook-pages-posts-collect-by-url)

## 按帖子 URL 获取帖子

**数据集 ID：** `gd_lyclm1571iy3mv57zw`

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

<Accordion title="示例响应">
  ```json theme={null}
  [
    {
      "url": "https://www.facebook.com/zuck/posts/example123",
      "post_text": "Excited to share...",
      "num_comments": 320,
      "date_posted": "2024-05-01T09:00:00.000Z",
      "reactions": 8500,
      "shares": 1200
    }
  ]
  ```
</Accordion>

[完整帖子响应模式](/cn/api-reference/scrapers/social-media-apis/facebook-posts-collect-by-url)

## 市场

**数据集 ID：** `gd_lvt9iwuh6fbcwmx1a`

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

<Accordion title="示例响应">
  ```json theme={null}
  [
    {
      "url": "https://www.facebook.com/marketplace/item/123456789",
      "title": "Vintage Coffee Table",
      "price": "$150",
      "location": "San Francisco, CA",
      "seller_name": "John Doe",
      "description": "Beautiful mid-century modern coffee table..."
    }
  ]
  ```
</Accordion>

[完整市场响应模式](/cn/api-reference/scrapers/social-media-apis/facebook-marketplace-collect-by-url)

## 评论

**数据集 ID：** `gd_lkay758p1eanlolqw8`

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

<Accordion title="示例响应">
  ```json theme={null}
  [
    {
      "url": "https://www.facebook.com/zuck/posts/example123",
      "comment_user": "Jane Smith",
      "comment_date": "2024-05-02T10:15:00.000Z",
      "comment_text": "Great update!",
      "reactions": 12,
      "replies_count": 3
    }
  ]
  ```
</Accordion>

[完整评论响应模式](/cn/api-reference/scrapers/social-media-apis/facebook-comments-collect-by-url)

## 快速参考：数据集 ID

| 端点               | 数据集 ID                  | URL 格式                                    |
| :--------------- | :---------------------- | :---------------------------------------- |
| 按个人资料 URL 获取页面帖子 | `gd_lkaxegm826bjpoo9m5` | `facebook.com/{page_name}`                |
| 评论               | `gd_lkay758p1eanlolqw8` | `facebook.com/{user}/posts/{post_id}`     |
| 按群组 URL 获取帖子     | `gd_lz11l67o2cb3r0lkj3` | `facebook.com/groups/{group_id}`          |
| 按帖子 URL 获取帖子     | `gd_lyclm1571iy3mv57zw` | `facebook.com/{user}/posts/{post_id}`     |
| 市场               | `gd_lvt9iwuh6fbcwmx1a`  | `facebook.com/marketplace/item/{item_id}` |
| 个人资料             | `gd_mf0urb782734ik94dz` | `facebook.com/{username}`                 |
| 页面和个人资料          | `gd_mf124a0511bauquyow` | `facebook.com/{page_or_profile}`          |
| 活动               | `gd_m14sd0to1jz48ppm51` | `facebook.com/events/{event_id}`          |
| 按个人资料 URL 获取短视频  | `gd_lyclm3ey2q6rww027t` | `facebook.com/{username}`                 |
| 公司评论             | `gd_m0dtqpiu1mbcyc2g86` | `facebook.com/{company_page}`             |

## 输出格式

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

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

## 相关内容

<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/facebook-profiles-collect-by-url">
    完整的参数和响应字段参考。
  </Card>
</CardGroup>
