# 百度贴吧 API | Baidu Tieba Search, Comments & User Posts (`socialdatax/socialdatax-baidu-tieba-data-api`) Actor

社媒数据助手 SocialDataX 提供百度贴吧帖子搜索、吧内搜索、贴吧帖子列表、评论与回复、用户资料及发帖。Baidu Tieba API for post search, search within a forum, forum threads, comments, replies and user posts. Export JSON, CSV, Excel. 无需配置 SocialDataX API Key。

- **URL**: https://apify.com/socialdatax/socialdatax-baidu-tieba-data-api.md
- **Developed by:** [SocialDataX](https://apify.com/socialdatax) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.99 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## 百度贴吧 API | SocialDataX Baidu Tieba

社媒数据助手 SocialDataX 提供百度贴吧帖子搜索、指定贴吧内搜索、贴吧帖子列表、评论与回复、用户资料及发帖。Baidu Tieba API for post search, forum threads, comments and user posts. 结果写入 Dataset，可导出 JSON、CSV、Excel，无需填写 SocialDataX API Key。

### 价格

每千条 Dataset 结果 **$2.99**（每条 $0.00299），所有操作统一计价。仅成功写入 Dataset 的结果按条计费，空结果不产生结果费用；每个启动事件另收 $0.00005，按 Apify 内存计费规则计算。运行中的平台费用包含在上述价格中。

### 选择能力

| operation | 必填 / 入口 | 分页 |
| --- | --- | --- |
| `search_posts` | keyword | 支持 |
| `search_general` | keyword | 支持 |
| `search_posts_in_forum` | forum_name, keyword | 支持 |
| `search_users` | keyword | 不支持 |
| `search_suggestions` | keyword | 不支持 |
| `get_post_detail` | thread_id / url（二选一） | 不支持 |
| `get_post_comments` | thread_id / url（二选一） | 支持 |
| `get_comment_replies` | thread_id, comment_id | 支持 |
| `get_user_info` | user_id / profile_url（二选一） | 不支持 |
| `list_user_posts` | user_id / profile_url（二选一） | 支持 |
| `list_user_followed_forums` | user_id / profile_url（二选一） | 支持 |
| `get_forum_detail` | forum_name | 不支持 |
| `list_forum_posts` | forum_name | 支持 |

### 使用说明

- ID 请以字符串传入，避免长整数精度丢失。使用搜索结果中的 ID 或链接，不要把链接放入 ID 字段。
- 评论回复需要内容 ID 和一级评论 ID，不要使用回复自身的 ID。
- 默认最多20条，上限1000条。自动分页只用于支持分页的操作；空页有令牌时仍会继续。
- 结果上限截断当前页时，OUTPUT 会提示续页令牌将跳过未导出条目；需要完整当前页时请提高上限。
- Dataset 保留完整字段，作者对象展开为 author\_\*；嵌套数组保留，预览视图不限制导出字段。
- 持续使用需要 Apify 付费计划；免费计划有5次 SocialDataX API 请求试用额度，分页与重试都会消耗次数。Apify 赠送金额与本试用请求额度分别计算。
- 综合搜索只返回其中的帖子。用户搜索不分页，精确和相关用户分别标记 match_type=exact/related，每个返回项单独计费。
- 搜索建议包含建议词和相关贴吧，分别标记 result_type=suggestion/forum；两类结果逐项导出，共同计入 max_items 和结果计费。
- 用户关注贴吧列表并非对所有用户均可读取；查询失败会报错，不会伪造为空列表。
- 帖子搜索排序：newest、oldest、relevance；吧内搜索：newest、relevance；评论：hot、newest、oldest；吧内列表：default、newest、latest_reply、hot。精华筛选 featured_only=true 仅支持 default。
- 用户资料、发帖及关注贴吧使用数字 user_id 或完整 profile_url 二选一；不要把主页中的 portrait 当成 user_id。

### 示例

#### 关键词搜索

```json
{
  "operation": "search_posts",
  "keyword": "美食",
  "max_items": 20,
  "auto_paginate": true
}
```

以下示例使用已验收的公开样本，每次最多导出3条、关闭自动分页，便于先确认返回内容。样本内容可能随平台变化。

#### 指定贴吧内搜索

forum_name 是贴吧名称，keyword 是要在该吧内搜索的词；只想浏览该吧帖子时使用 list_forum_posts。

```json
{
  "operation": "search_posts_in_forum",
  "forum_name": "方便面",
  "keyword": "方便面",
  "max_items": 3,
  "auto_paginate": false
}
```

#### 获取帖子评论

将 thread_id 换成帖子搜索结果中的帖子 ID；也可以改用 url，两个字段只填一个。楼中楼回复使用 get_comment_replies。

```json
{
  "operation": "get_post_comments",
  "thread_id": "11122226988",
  "max_items": 3,
  "auto_paginate": false
}
```

支持与接入：[SocialDataX](https://socialdatax.com/ai?from=apify)。

# Actor input Schema

## `operation` (type: `string`):

选择能力；仅填写对应字段。详情和资料查询支持 ID 或链接二选一。

## `keyword` (type: `string`):

搜索词或关键词短语，例如 方便面、旅行攻略；不要传帖子链接、帖子 ID 或分页令牌。需要限定某个贴吧时使用吧内帖子搜索。

## `page_token` (type: `string`):

首页留空；续页原样传回同一操作的完整 next_page_token，保持搜索词、ID、排序和筛选条件不变。

## `sort_type` (type: `string`):

可留空使用操作默认值：帖子/吧内搜索 newest；评论 hot；吧内列表 default。各操作只接受其支持的排序；精华帖只支持 default。

## `forum_name` (type: `string`):

准确贴吧名称，例如 方便面；直接使用结果中的 forum_name，不要自行追加“吧”字；不要传 URL 或数字 ID，无需 URL 编码。

## `thread_id` (type: `string`):

主题帖数字 ID，可取贴吧搜索结果的 thread_id；不要传帖子链接。

## `url` (type: `string`):

填写所选操作对应的完整链接，与该操作的 ID 二选一。不要同时填写 ID 和链接。

## `comment_id` (type: `string`):

一级评论 ID，取一级评论结果的 comment_id 或本工具结果的 parent_comment_id；不要传楼中楼回复自身的 comment_id。

## `user_id` (type: `string`):

百度贴吧数字用户 ID：用户搜索结果取 user_id；帖子搜索、帖子详情或评论结果中的作者取 author_user_id。不是主页链接中的 portrait 或 tieba_uid。

## `profile_url` (type: `string`):

填写所选操作对应的完整链接，与该操作的 ID 二选一。不要同时填写 ID 和链接。

## `featured_only` (type: `boolean`):

是否仅查看精华帖，false 表示不筛选（仍可包含精华帖）；true 时 sort_type 必须为 default，按贴吧精华列表顺序返回。

## `max_items` (type: `integer`):

列表总导出上限；详情与资料最多1条。仅成功写入 Dataset 的结果按条计费，另有启动费。

## `auto_paginate` (type: `boolean`):

有分页能力时自动续页，直到达到上限或令牌为空；空页有令牌仍会继续。无分页能力的操作只请求一次。

## Actor input object example

```json
{
  "operation": "search_posts",
  "keyword": "美食",
  "featured_only": false,
  "max_items": 20,
  "auto_paginate": true
}
```

# Actor output Schema

## `dataset` (type: `string`):

Open flat result rows written to the default Apify Dataset. Export as JSON, CSV, Excel / XLSX, or JSONL.

## `keyValueStore` (type: `string`):

Open the default key-value store. The OUTPUT record contains operation, item count, request count, page-level response summaries, non-fatal warnings, and lightweight failure details when a run fails.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("socialdatax/socialdatax-baidu-tieba-data-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("socialdatax/socialdatax-baidu-tieba-data-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call socialdatax/socialdatax-baidu-tieba-data-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,socialdatax/socialdatax-baidu-tieba-data-api"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/QFiOaoHXzyPScBYHh/builds/78zNS4if8XFb2tnpZ/openapi.json
