# 知乎 / Zhihu API - 搜索、回答文章、评论、用户数据 (`socialdatax/socialdatax-zhihu-data-api`) Actor

社媒数据助手 SocialDataX 提供的只读知乎 / Zhihu data API，支持知乎搜索 / Zhihu content search、回答和文章详情、评论 / comments、评论回复 / comment replies、用户资料 / creator profile 和用户文章列表，结果可导出 CSV、Excel、JSON 或通过 Apify API 使用。

- **URL**: https://apify.com/socialdatax/socialdatax-zhihu-data-api.md
- **Developed by:** [SocialDataX](https://apify.com/socialdatax) (community)
- **Categories:** Social media, Developer tools, Automation
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.99 / 1,000 dataset items

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js/docs.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python/docs.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## 知乎 / Zhihu Data API by SocialDataX

SocialDataX provides a read-only Zhihu / 知乎 data API on Apify. Use it to export structured Zhihu search results, answer/article/video details, comments, comment replies, creator profiles, and creator article lists into an Apify Dataset.

Apify users do not need to configure a SocialDataX API Key. The Actor owner configures `SOCIALDATAX_API_KEY` as an Apify secret.

### What It Supports

- `search_contents`: 知乎内容搜索 / Zhihu content search by keyword.
- `get_content_detail`: 回答、专栏文章、视频详情 / answer, article, or video details.
- `get_content_comments`: 一级评论 / top-level comments.
- `get_comment_replies`: 评论回复 / comment replies.
- `get_user_info`: 用户资料 / creator profile.
- `list_user_articles`: 用户发布文章列表 / creator articles.

### Input Example

```json
{
  "operation": "search_contents",
  "keyword": "露营",
  "content_type": "all",
  "sort_type": "general",
  "publish_time_range": "all",
  "page_token": "",
  "max_items": 20,
  "auto_paginate": true
}
````

`max_items` defaults to `50` and can be set up to `1000`. When `auto_paginate` is enabled, the Actor keeps requesting the next page until it reaches `max_items`, there is no next page, or a safety limit is reached. Each page request counts as one SocialDataX API request.

### Output

Results are written to the default Apify Dataset as flat rows. This makes the output easy to export as JSON, CSV, Excel / XLSX, JSONL, or consume from the Apify API.

Common fields include:

- Query fields: `query_keyword`, `query_content_url`, `query_profile_url`, `query_page_token`.
- Page fields: `page_request_index`, `page_item_count`, `page_next_page_token`, `page_has_more`.
- Content fields: `content_id`, `content_type`, `title`, `summary`, `content_url`, `upvote_count`, `comment_count`, `publish_time`.
- Author fields: `author_user_id`, `author_name`, `author_profile_url`, `author_follower_count`.
- Zhihu-specific objects flattened as `question_*`, `answer_*`, and `video_*`.

The `OUTPUT` key-value store record keeps a lightweight run summary with operation, request count, page summaries, warnings, and failure details. Full result rows are in the Dataset.

### API Usage

Run and get Dataset items synchronously:

```bash
curl "https://api.apify.com/v2/acts/socialdatax~socialdatax-zhihu-data-api/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "operation": "search_contents",
    "keyword": "露营",
    "content_type": "all",
    "sort_type": "general",
    "publish_time_range": "all",
    "max_items": 20,
    "auto_paginate": true
  }'
```

For detail and comment operations, use `content_url` returned by search/detail rows. Supported content URL examples:

- `https://www.zhihu.com/question/{question_id}/answer/{answer_id}`
- `https://zhuanlan.zhihu.com/p/{article_id}`
- `https://www.zhihu.com/zvideo/{video_id}`

For user operations, use a Zhihu profile URL like:

- `https://www.zhihu.com/people/{url_token}`

### Pricing

Recommended Apify Pay per event setup:

- `apify-default-dataset-item`: `$0.00399 / Dataset item`
- `apify-actor-start`: `$0.00005 / run`

### Operator Setup

Set these environment variables in Apify Console for the Actor owner:

- `SOCIALDATAX_API_KEY`: required, stored as an Apify secret.
- `SOCIALDATAX_API_BASE_URL`: optional, defaults to `https://mcp.socialdatax.com`.

For help, visit [socialdatax.com](https://socialdatax.com/).

# Actor input Schema

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

先选择要调用的知乎 / Zhihu 数据能力，然后只填写该 operation 需要的字段；无关字段会被忽略。Choose the operation first, then fill only the fields used by that operation.

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

仅 operation=search\_contents 时必填；其它 operation 可留空。Only required for Zhihu content search.

## `content_type` (type: `string`):

仅 operation=search\_contents 时使用。all=不限，answer=回答，article=文章，video=视频。

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

仅 operation=search\_contents 时使用。general=综合，upvote\_count\_descending=最多赞同，time\_descending=最新发布。

## `publish_time_range` (type: `string`):

仅 operation=search\_contents 时使用。选择知乎内容发布时间范围；无明确需求保持 all。

## `content_url` (type: `string`):

operation=get\_content\_detail、get\_content\_comments、get\_comment\_replies 时必填。请粘贴知乎回答、专栏文章或视频链接；问题页、用户主页、昵称和短链接不适用。支持示例：https://www.zhihu.com/question/{question\_id}/answer/{answer\_id}、https://zhuanlan.zhihu.com/p/{article\_id}、https://www.zhihu.com/zvideo/{video\_id}。

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

仅 operation=get\_comment\_replies 时必填。先运行 get\_content\_comments，在 Dataset 里找到 reply\_count > 0 的一级评论行，复制该行的 comment\_id；继续使用同一个 content\_url。

## `comment_sort_type` (type: `string`):

仅 operation=get\_content\_comments 时使用。default=默认，time\_descending=最新。

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

operation=get\_user\_info、list\_user\_articles 时必填。请粘贴知乎主页链接，例如 https://www.zhihu.com/people/{url\_token}；不要填昵称、回答链接、文章链接或问题页。

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

搜索、评论、评论回复、用户文章列表继续翻页时传入上一页返回的完整 next\_page\_token；第一页留空。auto\_paginate=true 时通常不用手动填写。

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

最多写入多少条 Dataset item。对搜索、评论、评论回复、用户文章列表用于限制自动翻页结果；较大的值可能触发多次 SocialDataX API request。

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

开启后 Actor 会按 next\_page\_token 继续请求，直到达到 max\_items 或没有下一页。关闭时只请求当前 page\_token。每翻一页计 1 次 SocialDataX API request。

## Actor input object example

```json
{
  "operation": "search_contents",
  "keyword": "露营",
  "content_type": "all",
  "sort_type": "general",
  "publish_time_range": "all",
  "comment_sort_type": "default",
  "max_items": 50,
  "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-zhihu-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-zhihu-data-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).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-zhihu-data-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=socialdatax/socialdatax-zhihu-data-api",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "知乎 / Zhihu API - 搜索、回答文章、评论、用户数据",
        "description": "社媒数据助手 SocialDataX 提供的只读知乎 / Zhihu data API，支持知乎搜索 / Zhihu content search、回答和文章详情、评论 / comments、评论回复 / comment replies、用户资料 / creator profile 和用户文章列表，结果可导出 CSV、Excel、JSON 或通过 Apify API 使用。",
        "version": "0.1",
        "x-build-id": "vskLEcYnZhilELnL6"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/socialdatax~socialdatax-zhihu-data-api/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-socialdatax-socialdatax-zhihu-data-api",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/socialdatax~socialdatax-zhihu-data-api/runs": {
            "post": {
                "operationId": "runs-sync-socialdatax-socialdatax-zhihu-data-api",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/socialdatax~socialdatax-zhihu-data-api/run-sync": {
            "post": {
                "operationId": "run-sync-socialdatax-socialdatax-zhihu-data-api",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "operation"
                ],
                "properties": {
                    "operation": {
                        "title": "操作 / Operation",
                        "enum": [
                            "search_contents",
                            "get_content_detail",
                            "get_content_comments",
                            "get_comment_replies",
                            "get_user_info",
                            "list_user_articles"
                        ],
                        "type": "string",
                        "description": "先选择要调用的知乎 / Zhihu 数据能力，然后只填写该 operation 需要的字段；无关字段会被忽略。Choose the operation first, then fill only the fields used by that operation.",
                        "default": "search_contents"
                    },
                    "keyword": {
                        "title": "关键词 / Keyword",
                        "type": "string",
                        "description": "仅 operation=search_contents 时必填；其它 operation 可留空。Only required for Zhihu content search.",
                        "default": "露营"
                    },
                    "content_type": {
                        "title": "内容类型 / Content type",
                        "enum": [
                            "all",
                            "answer",
                            "article",
                            "video"
                        ],
                        "type": "string",
                        "description": "仅 operation=search_contents 时使用。all=不限，answer=回答，article=文章，video=视频。",
                        "default": "all"
                    },
                    "sort_type": {
                        "title": "搜索排序 / Search sort",
                        "enum": [
                            "general",
                            "upvote_count_descending",
                            "time_descending"
                        ],
                        "type": "string",
                        "description": "仅 operation=search_contents 时使用。general=综合，upvote_count_descending=最多赞同，time_descending=最新发布。",
                        "default": "general"
                    },
                    "publish_time_range": {
                        "title": "发布时间 / Publish time",
                        "enum": [
                            "all",
                            "day",
                            "week",
                            "month",
                            "three_months",
                            "half_year",
                            "year"
                        ],
                        "type": "string",
                        "description": "仅 operation=search_contents 时使用。选择知乎内容发布时间范围；无明确需求保持 all。",
                        "default": "all"
                    },
                    "content_url": {
                        "title": "内容链接 / Content URL",
                        "type": "string",
                        "description": "operation=get_content_detail、get_content_comments、get_comment_replies 时必填。请粘贴知乎回答、专栏文章或视频链接；问题页、用户主页、昵称和短链接不适用。支持示例：https://www.zhihu.com/question/{question_id}/answer/{answer_id}、https://zhuanlan.zhihu.com/p/{article_id}、https://www.zhihu.com/zvideo/{video_id}。"
                    },
                    "comment_id": {
                        "title": "一级评论 ID / Comment ID",
                        "type": "string",
                        "description": "仅 operation=get_comment_replies 时必填。先运行 get_content_comments，在 Dataset 里找到 reply_count > 0 的一级评论行，复制该行的 comment_id；继续使用同一个 content_url。"
                    },
                    "comment_sort_type": {
                        "title": "评论排序 / Comment sort",
                        "enum": [
                            "default",
                            "time_descending"
                        ],
                        "type": "string",
                        "description": "仅 operation=get_content_comments 时使用。default=默认，time_descending=最新。",
                        "default": "default"
                    },
                    "profile_url": {
                        "title": "主页链接 / Profile URL",
                        "type": "string",
                        "description": "operation=get_user_info、list_user_articles 时必填。请粘贴知乎主页链接，例如 https://www.zhihu.com/people/{url_token}；不要填昵称、回答链接、文章链接或问题页。"
                    },
                    "page_token": {
                        "title": "分页令牌 / Page token",
                        "type": "string",
                        "description": "搜索、评论、评论回复、用户文章列表继续翻页时传入上一页返回的完整 next_page_token；第一页留空。auto_paginate=true 时通常不用手动填写。"
                    },
                    "max_items": {
                        "title": "最大结果数 / Max items",
                        "minimum": 1,
                        "maximum": 1000,
                        "type": "integer",
                        "description": "最多写入多少条 Dataset item。对搜索、评论、评论回复、用户文章列表用于限制自动翻页结果；较大的值可能触发多次 SocialDataX API request。",
                        "default": 50
                    },
                    "auto_paginate": {
                        "title": "自动翻页 / Auto paginate",
                        "type": "boolean",
                        "description": "开启后 Actor 会按 next_page_token 继续请求，直到达到 max_items 或没有下一页。关闭时只请求当前 page_token。每翻一页计 1 次 SocialDataX API request。",
                        "default": true
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
