# 知乎 / 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:** 1 total users, 1 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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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.

### Use Cases

- Export Zhihu search results for a given keyword or topic.
- Retrieve detailed content for Zhihu answers, articles, and videos.
- Export top-level comments and comment replies for analysis.
- Gather creator profile information and creator article lists.
- Use automatic pagination export with configurable maximum items.

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

Download the OpenAPI definition: https://api.apify.com/v2/actors/Nh8NxQ52hnAEdyCL8/builds/TvOFrn2Oqww5zm8wW/openapi.json
