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

# 如何通过webhook接收LinkedIn数据

> 配置webhook交付，在集合完成后立即将爬取的LinkedIn数据接收到您的HTTP端点。

本指南向您展示如何设置webhook交付，以便在集合任务完成时您的服务器自动接收爬取的LinkedIn数据。

## 先决条件

* 一个[Bright Data账户](https://www.bright.cn/cp/start)，配有有效的API密钥
* 熟悉[异步请求工作流](/cn/datasets/scrapers/linkedin/async-requests)
* 一个可公开访问的HTTP端点（或使用测试工具如[webhook.site](https://webhook.site)）

## Webhook如何工作

当您触发带有`endpoint` URL的异步集合时，Bright Data会在任务完成后向您的端点发送一个`POST`请求，携带爬取的数据。无需轮询。

```
您的应用 --> POST /trigger (带webhook URL) --> Bright Data爬取 --> POST到您的webhook
```

## 第1步：设置测试webhook

为了测试，使用[webhook.site](https://webhook.site)获取临时公共URL：

1. 在浏览器中打开[webhook.site](https://webhook.site)
2. 复制显示的唯一URL（例如，`https://webhook.site/abc-123-def`）
3. 保持页面打开以监控传入的请求

## 第2步：使用webhook URL触发集合

在异步`/trigger`请求中添加`endpoint`查询参数：

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    "https://api.brightdata.com/datasets/v3/trigger?dataset_id=gd_l1viktl72bvl7bjuj0&format=json&endpoint=https://webhook.site/abc-123-def&uncompressed_webhook=true" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '[
      {"url": "https://www.linkedin.com/in/satyanadella"},
      {"url": "https://www.linkedin.com/in/jeffweiner08"}
    ]'
  ```

  ```python Python theme={null}
  import requests

  WEBHOOK_URL = "https://webhook.site/abc-123-def"

  response = requests.post(
      "https://api.brightdata.com/datasets/v3/trigger",
      params={
          "dataset_id": "gd_l1viktl72bvl7bjuj0",
          "format": "json",
          "webhook": WEBHOOK_URL,
          "uncompressed_webhook": "true",
      },
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
          "Content-Type": "application/json",
      },
      json=[
          {"url": "https://www.linkedin.com/in/satyanadella"},
          {"url": "https://www.linkedin.com/in/jeffweiner08"},
      ],
  )

  print("Snapshot ID:", response.json()["snapshot_id"])
  ```

  ```javascript Node.js theme={null}
  const WEBHOOK_URL = "https://webhook.site/abc-123-def";

  const response = await fetch(
    `https://api.brightdata.com/datasets/v3/trigger?dataset_id=gd_l1viktl72bvl7bjuj0&format=json&endpoint=${encodeURIComponent(WEBHOOK_URL)}&uncompressed_webhook=true`,
    {
      method: "POST",
      headers: {
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify([
        { url: "https://www.linkedin.com/in/satyanadella" },
        { url: "https://www.linkedin.com/in/jeffweiner08" },
      ]),
    }
  );

  const data = await response.json();
  console.log("Snapshot ID:", data.snapshot_id);
  ```
</CodeGroup>

关键参数：

| 参数                     | 描述                            |
| :--------------------- | :---------------------------- |
| `endpoint`             | 接收`POST`负载的HTTP端点URL          |
| `uncompressed_webhook` | 设置为`true`以接收未压缩的JSON（默认为gzip） |
| `format`               | 输出格式：`json`、`ndjson`或`csv`    |

## 第3步：验证交付

集合完成后（通常需要30-60秒来处理几个档案），检查您的webhook.site页面。您应该看到一个包含爬取数据的`POST`请求。

负载与您从直接API下载接收的JSON数组相同：

```json theme={null}
[
  {
    "name": "Satya Nadella",
    "city": "Redmond",
    "country_code": "US",
    "current_company": { "name": "Microsoft" },
    "followers": 10842560
  },
  {
    "name": "Jeff Weiner",
    "city": "San Francisco Bay Area",
    "country_code": "US",
    "current_company": { "name": "Next Chapter" },
    "followers": 1200000
  }
]
```

## 生产环境webhook设置

对于生产环境，将`endpoint` URL指向您自己的服务器端点。

### Express.js处理程序

```javascript server.js theme={null}
const express = require("express");
const app = express();

app.use(express.json({ limit: "100mb" }));

app.post("/webhook/linkedin", (req, res) => {
  const profiles = req.body;
  console.log(`Received ${profiles.length} profiles`);

  for (const profile of profiles) {
    console.log(`- ${profile.name} (${profile.current_company?.name})`);
  }

  res.status(200).json({ received: true });
});

app.listen(3000, () => console.log("Webhook server running on port 3000"));
```

### Flask处理程序

```python server.py theme={null}
from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route("/webhook/linkedin", methods=["POST"])
def handle_webhook():
    profiles = request.get_json()
    print(f"Received {len(profiles)} profiles")

    for profile in profiles:
        print(f"- {profile['name']} ({profile.get('current_company', {}).get('name')})")

    return jsonify({"received": True}), 200

if __name__ == "__main__":
    app.run(port=3000)
```

<Warning>
  在30秒内返回`200`状态码以确认收到。如果您的端点失败或超时，Bright Data会重试交付。
</Warning>

## 带授权的Webhook

如果您的端点需要身份验证，添加`webhook_header_Authorization`参数：

```bash theme={null}
curl -X POST \
  "https://api.brightdata.com/datasets/v3/trigger?dataset_id=gd_l1viktl72bvl7bjuj0&format=json&endpoint=https://your-server.com/webhook&webhook_header_Authorization=Bearer+YOUR_SECRET_TOKEN" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{"url": "https://www.linkedin.com/in/satyanadella"}]'
```

## 允许列表webhook IP

如果您的服务器使用IP允许列表，请添加以下Bright Data webhook源IP：

```
54.175.27.69
34.225.9.175
100.28.38.247
100.29.18.195
52.72.185.255
35.174.112.248
54.165.183.124
3.91.140.7
52.202.75.37
98.82.225.117
100.27.150.189
18.214.10.85
35.169.71.210
44.194.183.74
```

## 故障排除

<Accordion title="Webhook未接收数据？">
  * 验证URL是否可公开访问（不是`localhost`）
  * 检查您的端点是否在30秒内返回`200`状态码
  * 如果您有防火墙规则，验证上述webhook IP是否在允许列表中
</Accordion>

<Accordion title="接收压缩数据？">
  如果您省略`uncompressed_webhook=true`，数据将以gzip压缩格式到达。将`uncompressed_webhook=true`添加到您的触发URL，或在您的服务器上解压负载。
</Accordion>

<Accordion title="负载对您���服务器来说太大？">
  大型集合可能会产生高达1 GB的负载。在Express.js中设置`express.json({ limit: "100mb" })`或在您的框架中设置等效配置。如果您需要处理非常大的数据集，改用[S3交付](/cn/datasets/scrapers/linkedin/data-delivery/amazon-s3)。
</Accordion>

## 后续步骤

<CardGroup cols={2}>
  <Card title="交付到Amazon S3" icon="bucket" href="/cn/datasets/scrapers/linkedin/data-delivery/amazon-s3">
    直接在您的S3存储桶中存储结果。
  </Card>

  <Card title="所有交付选项" icon="truck" href="/cn/datasets/scrapers/scrapers-library/delivery-options">
    Snowflake、Azure、GCS等。
  </Card>
</CardGroup>
