知乎关键词搜索 API (V1)
接口健康状态
健康 可用 少量可用 基本不可用 暂无数据
正在加载健康状态…
按关键词搜索知乎,可选的搜索结果类型、排序、时间间隔、话题显示和偏移量控制。用于查找相关的回答、文章或视频。
请求参数
| 参数名 | 位置 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|---|
token | query | string | 是 | - | TOKEN |
keyword | query | string | 是 | - | 搜索关键词。 |
offset | query | integer | 否 | 0 | 起始偏移量,从0开始。 |
showAllTopics | query | string | 否 | FALSE | 是否显示所有话题。 可选值: - FALSE: 不显示话题。- TRUE: 显示所有话题。 |
vertical | query | string | 否 | - | 结果类型筛选。 可选值: - answer: 仅回答。- article: 仅文章。- zvideo: 仅视频。 |
sort | query | string | 否 | - | 排序条件。 可选值: - upvoted_count: 最多点赞。- created_time: 最新发布。 |
timeInterval | query | string | 否 | - | 发布时间间隔筛选。 可选值: - a_day: 一天内。- a_week: 一周内。- a_month: 一个月内。- three_months: 三个月内。- half_a_year: 半年内。- a_year: 一年内。 |
代码示例
bash
curl --max-time 120 -X GET 'https://api.justoneapi.com/api/zhihu/search/v1?token=YOUR_API_KEY&keyword=VALUE'text
我想使用 JustOneAPI 提供的“关键词搜索 (V1)”接口。
接入地址: https://api.justoneapi.com。
接口路径: /api/zhihu/search/v1?token=YOUR_API_KEY&keyword=VALUE
接口地址: BASE_URL + /api/zhihu/search/v1?token=YOUR_API_KEY&keyword=VALUE
HTTP 方法: GET
身份验证: 在 URL 中传入 token 查询参数。
OpenAPI 定义: https://docs.justoneapi.com/openapi/zhihu/keyword-search-v1-zh.json
请求参数说明:
- token (query): TOKEN (必填)
- keyword (query): 搜索关键词。 (必填)
- offset (query): 起始偏移量,从0开始。
- showAllTopics (query): 是否显示所有话题。
可选值:
- `FALSE`: 不显示话题。
- `TRUE`: 显示所有话题。
- vertical (query): 结果类型筛选。
可选值:
- `answer`: 仅回答。
- `article`: 仅文章。
- `zvideo`: 仅视频。
- sort (query): 排序条件。
可选值:
- `upvoted_count`: 最多点赞。
- `created_time`: 最新发布。
- timeInterval (query): 发布时间间隔筛选。
可选值:
- `a_day`: 一天内。
- `a_week`: 一周内。
- `a_month`: 一个月内。
- `three_months`: 三个月内。
- `half_a_year`: 半年内。
- `a_year`: 一年内。
返回格式: 请根据实际 Content-Type 安全处理 JSON 或文本响应。
响应处理与错误码:
1. 需通过返回体中的 "code" 字段判断业务结果(code 为 0 表示成功)。
2. 超时建议:建议将请求超时时间设置为 120 秒;如果 120 秒偏长,请至少设置为 60 秒,但可能会有少量请求因超时而未接收到结果。
3. 业务码说明:
- 0: 成功
- 100: Token 无效或已失效
- 301: 采集失败,请重试
- 302: 超出速率限制
- 303: 超出每日配额
- 400: 参数错误
- 500: 内部服务器错误
- 600: 权限不足
- 601: 账户余额不足
- 602: TOKEN 限额超限
4. code 601 表示账户共享余额不足。code 602 表示当前 API TOKEN 自身的累计消费上限已达到。TOKEN 限额不是资金划拨,多个 TOKEN 仍共享同一个账户余额。
请帮我用我擅长的编程语言写一个脚本来调用这个接口,并处理返回结果。python
import requests
BASE_URL = "https://api.justoneapi.com" # 由 OpenAPI servers 提供
url = BASE_URL + "/api/zhihu/search/v1?token=YOUR_API_KEY&keyword=VALUE"
response = requests.get(url, timeout=120)
print(response.status_code)
if response.content:
content_type = response.headers.get("content-type", "").lower()
if "json" in content_type:
try:
print(response.json())
except ValueError:
print(response.text)
elif content_type.startswith("text/") or "xml" in content_type or content_type.split(";", 1)[0].strip() in {"application/javascript", "application/x-www-form-urlencoded", "application/graphql"}:
print(response.text)
else:
with open("response.bin", "wb") as output:
output.write(response.content)
print(f"Saved {len(response.content)} bytes to response.bin")js
const BASE_URL = "https://api.justoneapi.com"; // 由 OpenAPI servers 提供
const url = BASE_URL + "/api/zhihu/search/v1?token=YOUR_API_KEY&keyword=VALUE";
const response = await fetch(url, {
method: "GET",
signal: AbortSignal.timeout(120000)
});
console.log(response.status);
const responseBytes = await response.arrayBuffer();
if (responseBytes.byteLength) {
const contentType = (response.headers.get("content-type") || "").toLowerCase();
const mediaType = contentType.split(";", 1)[0].trim();
const textual = contentType.startsWith("text/") || contentType.includes("json") || contentType.includes("xml") || ["application/javascript", "application/x-www-form-urlencoded", "application/graphql"].includes(mediaType);
if (textual) {
const responseText = new TextDecoder().decode(responseBytes);
let data = responseText;
if (contentType.includes("json")) {
try { data = JSON.parse(responseText); } catch { /* Keep the raw body. */ }
}
console.log(data);
} else {
console.log(`Received ${responseBytes.byteLength} binary bytes`);
}
}java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
public class Main {
public static void main(String[] args) throws Exception {
final String BASE_URL = "https://api.justoneapi.com"; // 由 OpenAPI servers 提供
final String url = BASE_URL + "/api/zhihu/search/v1?token=YOUR_API_KEY&keyword=VALUE";
HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(120)).build();
HttpRequest.Builder builder = HttpRequest.newBuilder()
.uri(URI.create(url))
.timeout(Duration.ofSeconds(120))
.method("GET", HttpRequest.BodyPublishers.noBody());
HttpRequest request = builder.build();
HttpResponse<byte[]> response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
System.out.println(response.statusCode());
String contentType = response.headers().firstValue("content-type").orElse("").toLowerCase();
String mediaType = contentType.split(";", 2)[0].trim();
if (contentType.startsWith("text/") || contentType.contains("json") || contentType.contains("xml") || mediaType.equals("application/javascript") || mediaType.equals("application/x-www-form-urlencoded") || mediaType.equals("application/graphql")) {
System.out.println(new String(response.body(), StandardCharsets.UTF_8));
} else {
Files.write(Path.of("response.bin"), response.body());
System.out.println("Saved " + response.body().length + " bytes to response.bin");
}
}
}go
package main
import (
"fmt"
"io"
"os"
"strings"
"net/http"
"time"
)
const BASE_URL = "https://api.justoneapi.com" // 由 OpenAPI servers 提供
func main() {
client := &http.Client{Timeout: 120 * time.Second}
url := BASE_URL + "/api/zhihu/search/v1?token=YOUR_API_KEY&keyword=VALUE"
req, _ := http.NewRequest("GET", url, nil)
resp, _ := client.Do(req)
defer resp.Body.Close()
fmt.Println(resp.StatusCode)
bodyBytes, _ := io.ReadAll(resp.Body)
contentType := strings.ToLower(resp.Header.Get("Content-Type"))
mediaType := strings.TrimSpace(strings.SplitN(contentType, ";", 2)[0])
if strings.HasPrefix(contentType, "text/") || strings.Contains(contentType, "json") || strings.Contains(contentType, "xml") || mediaType == "application/javascript" || mediaType == "application/x-www-form-urlencoded" || mediaType == "application/graphql" {
fmt.Println(string(bodyBytes))
} else {
os.WriteFile("response.bin", bodyBytes, 0600)
fmt.Printf("Saved %d bytes to response.bin\n", len(bodyBytes))
}
}php
<?php
$BASE_URL = 'https://api.justoneapi.com'; // 由 OpenAPI servers 提供
$url = $BASE_URL . '/api/zhihu/search/v1?token=YOUR_API_KEY&keyword=VALUE';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$contentType = strtolower((string) curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
curl_close($ch);
echo $status . PHP_EOL;
$mediaType = trim(explode(';', $contentType, 2)[0]);
if (str_starts_with($contentType, 'text/') || str_contains($contentType, 'json') || str_contains($contentType, 'xml') || in_array($mediaType, ['application/javascript', 'application/x-www-form-urlencoded', 'application/graphql'], true)) {
echo $response;
} else {
file_put_contents('response.bin', $response);
echo 'Saved ' . strlen($response) . ' bytes to response.bin' . PHP_EOL;
}返回字段
业务成功时(code = 0)的主要返回字段。
搜索结果与分页5 个字段
data
成功响应的 data 为对象时,包含关键词搜索结果和分页信息。
| 字段 | 类型 | 说明 |
|---|---|---|
paging | object | 本次搜索结果的分页状态。 |
paging.is_end | boolean | 本次响应是否标记搜索结果已结束。该值为 true 时停止翻页,即便仍返回 next。 |
paging.next | string | 知乎返回的分页链接。is_end 为 false 时,取链接中的 offset 再次调用本接口,并保持关键词和筛选条件不变。 |
data | array | 指定偏移量对应的搜索结果卡片。列表可以为空,卡片类型和返回字段可能不同。 |
related_search_result | array | 知乎返回的相关搜索结果,列表可以为空。 |
搜索卡片8 个字段
data.data[]
一张搜索结果卡片。
| 字段 | 类型 | 说明 |
|---|---|---|
id | integer | string | 搜索结果卡片自身的标识,有该字段时返回。 |
type | string | 搜索结果卡片的类型。 |
index | integer | 平台返回的卡片结果索引。 |
highlight | object | null | 命中内容的高亮信息,有该字段时返回。 |
highlight.title | string | 卡片中的高亮标题文本。 |
highlight.description | string | 卡片中的高亮简介文本。 |
highlight.name | string | 卡片中的高亮名称。 |
highlight.creator | string | 卡片中的高亮创作者名称。 |
内容信息13 个字段
data.data[].object
卡片关联的内容,可以是回答、文章、问题、用户资料或视频。字段随内容类型而异。
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 卡片关联内容的标识,有该字段时返回。 |
type | string | 卡片关联内容的类型。 |
title | string | 关联内容的标题,有该字段时返回。 |
description | string | object | 接口返回的内容简介。部分卡片类型会提供结构化简介。 |
raw_description | string | 视频返回的原始简介字符串。 |
excerpt | string | 接口返回的内容摘要,可能包含 HTML。 |
content | string | 接口返回的正文,可能包含 HTML。 |
url | string | 平台返回的该内容对应的知乎链接。 |
redirect_url | string | 卡片的跳转目标链接,有该字段时返回。 |
image_url | string | 卡片的图片链接。 |
is_anonymous | boolean | 平台返回的内容匿名标记。 |
created_time | integer | 平台返回的内容创建时间,使用 Unix 秒。 |
updated_time | integer | 平台返回的内容最后更新时间,使用 Unix 秒。 |
互动统计7 个字段
data.data[].object
| 字段 | 类型 | 说明 |
|---|---|---|
voteup_count | integer | 平台返回的内容或用户获赞同数。 |
comment_count | integer | 平台返回的内容评论数。 |
favorites_count | integer | 平台返回的内容收藏数。 |
visits_count | integer | 平台返回的内容访问数。 |
answer_count | integer | 平台返回的问题或用户回答数。 |
articles_count | integer | 平台返回的用户文章数。 |
follower_count | integer | 平台返回的用户或问题关注数。 |
关联问题5 个字段
data.data[].object.question
回答关联的问题。
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 知乎问题标识。 |
name | string | 回答关联的问题标题。 |
type | string | 关联问题对象的类型。 |
url | string | 关联问题的链接。 |
answer_count | integer | 平台返回的关联问题回答数。 |
用户与作者15 个字段
data.data[].object
| 字段 | 类型 | 说明 |
|---|---|---|
name | string | 用户资料结果的显示名称。 |
headline | string | 用户资料结果中的个人简介。 |
avatar_url | string | 用户资料的头像地址。 |
url_token | string | 知乎用户主页链接中使用的公开标识。 |
author | object | 关联内容的作者资料。 |
author.id | string | 作者资料标识。 |
author.url_token | string | 知乎作者主页链接中使用的公开标识。 |
author.name | string | 作者的展示名称。 |
author.headline | string | 作者个人简介。 |
author.avatar_url | string | 作者头像链接。 |
author.url | string | 接口返回的作者主页链接。 |
author.type | string | 作者资料对象的类型。 |
author.follower_count | integer | 平台返回的作者粉丝数。 |
author.voteup_count | integer | 平台返回的作者获赞同数。 |
creator | string | 视频结果返回的创作者名称文本。 |
视频信息17 个字段
data.data[].object
| 字段 | 类型 | 说明 |
|---|---|---|
zvideo_id | string | 知乎视频内容的标识。 |
video_id | string | 视频媒体标识。 |
video_url | string | 搜索结果返回的视频链接。 |
video_answer_url | string | 视频关联的回答链接,有该字段时返回。 |
cover_url | string | 视频封面图片地址。 |
created_at | integer | 接口返回的视频创建时间戳。 |
updated_at | integer | 接口返回的视频最后更新时间戳。 |
duration | number | 平台返回的视频时长数值。 |
width | integer | 视频宽度,单位为像素。 |
height | integer | 视频高度,单位为像素。 |
play_count | integer | 平台返回的视频播放次数。 |
video_info | object | 视频附带的媒体信息。 |
video_info.video_id | string | 视频媒体标识。 |
video_info.duration | number | 视频信息中的时长数值。 |
video_info.width | integer | 视频宽度,单位为像素。 |
video_info.height | integer | 视频高度,单位为像素。 |
video_info.play_count | integer | 视频信息中的播放数。 |
播放流28 个字段
data.data[].object.playlist
按画质标识组织的播放流。可用的播放流随视频而异。
| 字段 | 类型 | 说明 |
|---|---|---|
ld | object | 画质标识为 LD 的播放流,有该字段时返回。 |
ld.url | string | 对应播放流的媒体链接。 |
ld.play_url | string | 对应播放流的播放链接。 |
ld.width | integer | 播放流的画面宽度,单位为像素。 |
ld.height | integer | 播放流的画面高度,单位为像素。 |
ld.format | string | 平台返回的播放流媒体格式。 |
ld.quality | string | 平台返回的播放流画质标签。 |
sd | object | 画质标识为 SD 的播放流,有该字段时返回。 |
sd.url | string | 对应播放流的媒体链接。 |
sd.play_url | string | 对应播放流的播放链接。 |
sd.width | integer | 播放流的画面宽度,单位为像素。 |
sd.height | integer | 播放流的画面高度,单位为像素。 |
sd.format | string | 平台返回的播放流媒体格式。 |
sd.quality | string | 平台返回的播放流画质标签。 |
hd | object | 画质标识为 HD 的播放流,有该字段时返回。 |
hd.url | string | 对应播放流的媒体链接。 |
hd.play_url | string | 对应播放流的播放链接。 |
hd.width | integer | 播放流的画面宽度,单位为像素。 |
hd.height | integer | 播放流的画面高度,单位为像素。 |
hd.format | string | 平台返回的播放流媒体格式。 |
hd.quality | string | 平台返回的播放流画质标签。 |
fhd | object | 画质标识为 FHD 的播放流,有该字段时返回。 |
fhd.url | string | 对应播放流的媒体链接。 |
fhd.play_url | string | 对应播放流的播放链接。 |
fhd.width | integer | 播放流的画面宽度,单位为像素。 |
fhd.height | integer | 播放流的画面高度,单位为像素。 |
fhd.format | string | 平台返回的播放流媒体格式。 |
fhd.quality | string | 平台返回的播放流画质标签。 |
响应示例
正在加载响应示例…