跳至主要內容

知乎關鍵詞搜索 API (V1) ​

GET
API 端點健康狀態
健康 可用 少量可用 基本不可用 暫無資料
正在載入健康狀態…

按關鍵詞搜索知乎,可選的搜索結果類型、排序、時間間隔、話題顯示和偏移量控制。用於查找相關的回答、文章或視頻。

請求參數 ​

參數名 位置 類型 必填 預設值 說明
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-hant.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 平台返回的播放流畫質標籤。

回應示例 ​

正在載入回應範例…