跳至主要內容

Reddit帖子評論 API (V1) ​

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

獲取Reddit帖子的評論,支持分頁令牌。用於審查帖子的討論或繼續查看已知帖子的其他評論結果。

請求參數 ​

參數名 位置 類型 必填 預設值 說明
token query string 是 - 此 API 服務的訪問令牌。
postId query string 是 - Reddit帖子的唯一標識符。
cursor query string 否 下一頁結果的分頁令牌。

程式碼範例 ​

bash
curl --max-time 120 -X GET 'https://api.justoneapi.com/api/reddit/get-post-comments/v1?token=YOUR_API_KEY&postId=VALUE'
text
我想使用 JustOneAPI 提供的“帖子評論 (V1)”接口。
接入地址: https://api.justoneapi.com。
接口路徑: /api/reddit/get-post-comments/v1?token=YOUR_API_KEY&postId=VALUE
接口地址: BASE_URL + /api/reddit/get-post-comments/v1?token=YOUR_API_KEY&postId=VALUE
HTTP 方法: GET
身份驗證: 在 URL 中傳入 token 查詢參數。
OpenAPI 定義: https://docs.justoneapi.com/openapi/reddit/post-comments-v1-zh-hant.json

請求參數說明:
- token (query): 此 API 服務的訪問令牌。 (必填)
- postId (query): Reddit帖子的唯一標識符。 (必填)
- cursor (query): 下一頁結果的分頁令牌。

返回格式: 請根據實際 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/reddit/get-post-comments/v1?token=YOUR_API_KEY&postId=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/reddit/get-post-comments/v1?token=YOUR_API_KEY&postId=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/reddit/get-post-comments/v1?token=YOUR_API_KEY&postId=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/reddit/get-post-comments/v1?token=YOUR_API_KEY&postId=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/reddit/get-post-comments/v1?token=YOUR_API_KEY&postId=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)的主要返回欄位。

帖子與分頁9 個欄位

data

Reddit 帖子評論、討論串資料和分支續讀信息。

欄位 類型 說明
postInfoById object 指定帖子標識返回的帖子資料和評論樹。
postInfoById.id string Reddit 帖子標識。
postInfoById.title string Reddit 帖子標題。
postInfoById.commentCount integer 帖子返回的評論總數。
postInfoById.commentForest object 由父級標識關聯的評論和續讀條目列表。
postInfoById.commentForest.pageInfo object 評論樹返回的分頁信息。
postInfoById.commentForest.pageInfo.commentCount integer | null 評論樹返回的評論數量,不可用時為 null。
postInfoById.commentForest.pageInfo.hasNextPage boolean 該評論樹是否報告還有後續結果。
postInfoById.commentForest.trees array 評論樹返回的有序條目。每個條目可以是評論節點或續讀標記。
評論樹與分支續讀8 個欄位

data.postInfoById.commentForest.trees[]

評論樹中的一條評論或續讀條目。

欄位 類型 說明
childCount integer 該樹條目返回的子節點數量。
depth integer 評論條目在討論串中的深度,頂層條目深度為 0。
parentId string | null 父級評論標識,頂層條目可以返回 null。
node object | null 該樹條目附帶的評論內容和公開資料,續讀標記可返回 null。
more object | null 該分支的續讀信息,不可用時為 null。
more.count integer 該續讀條目返回的評論數量。
more.cursor string 該分支的續讀游標。使用相同 postId 時,將它原樣傳入 cursor 查詢參數。
more.isTooDeepForCount boolean 該分支是否因層級過深而無法提供計數。
評論正文14 個欄位

data.postInfoById.commentForest.trees[].node

欄位 類型 說明
id string Reddit 評論標識。
createdAt string 評論創建時間,以 ISO 日期時間字符串返回。
editedAt - 評論最近一次編輯的時間信息。已覈驗的樣本返回 null。
permalink string 評論的 Reddit 永久連結路徑。
content object 該評論返回的正文格式。
content.markdown string 以 Markdown 格式返回的評論正文。
content.preview string 返回的評論預覽文字。
content.richtext string 序列化為 JSON 字符串的富文本文件。
content.richtextMedia array 富文本引用的媒體條目,已覈驗的樣本返回空列表。
content.typeHint string 評論正文返回的內容類型提示。
content.translationInfo object 評論正文的翻譯狀態信息。
content.translationInfo.isTranslated boolean 返回的評論正文是否標記為已翻譯。
content.translationInfo.translatedLanguage - 評論翻譯正文的語言信息。已覈驗的樣本返回 null。
languageCode string | null 評論返回的語言代碼,不可用時為 null。
評論狀態與分數11 個欄位

data.postInfoById.commentForest.trees[].node

欄位 類型 說明
score integer Reddit 返回的評論分數。
isScoreHidden boolean 評論分數是否標記為已隱藏。
isAdminTakedown boolean 評論是否標記為已由 Reddit 管理員下架。
isArchived boolean 評論是否標記為已歸檔。
isCommercialCommunication boolean 評論是否標記為商業溝通內容。
isLocked boolean 評論是否標記為已鎖定。
isRemoved boolean 評論是否標記為已移除。
isStickied boolean 評論是否標記為已置頂。
isTranslatable boolean 評論是否標記為可翻譯。
removedByCategory - 評論返回的移除類別信息。已覈驗的樣本返回 null。
distinguishedAs - 評論返回的角色標記信息。已覈驗的樣本返回 null。
公開作者資料與徽章29 個欄位

data.postInfoById.commentForest.trees[].node

欄位 類型 說明
authorInfo object 評論作者返回的 Reddit 公開帳號資料。
authorInfo.id string 評論作者的 Reddit 帳號標識。
authorInfo.name string 評論作者展示的公開帳號名稱。
authorInfo.accountType string 評論作者返回的帳號類型。
authorInfo.iconSmall object 返回的作者小尺寸頭像。
authorInfo.iconSmall.dimensions object 圖片的像素尺寸。
authorInfo.iconSmall.dimensions.height integer 圖片高度,單位為像素。
authorInfo.iconSmall.dimensions.width integer 圖片寬度,單位為像素。
authorInfo.iconSmall.url string 返回的 Reddit 公開頭像圖片連結。
authorInfo.newIcon object 新版頭像欄位返回的頭像圖片。
authorInfo.newIcon.dimensions object 圖片的像素尺寸。
authorInfo.newIcon.dimensions.height integer 圖片高度,單位為像素。
authorInfo.newIcon.dimensions.width integer 圖片寬度,單位為像素。
authorInfo.newIcon.url string 返回的 Reddit 公開頭像圖片連結。
authorInfo.snoovatarIcon object | null 返回的作者 Snoovatar 形象圖片,不可用時為 null。
authorInfo.snoovatarIcon.dimensions object 圖片的像素尺寸。
authorInfo.snoovatarIcon.dimensions.height integer 圖片高度,單位為像素。
authorInfo.snoovatarIcon.dimensions.width integer 圖片寬度,單位為像素。
authorInfo.snoovatarIcon.url string 返回的 Reddit 公開頭像圖片連結。
authorInfo.isCakeDayNow boolean 作者帳號是否標記為正在慶祝 Reddit 註冊週年。
authorInfo.profile object 評論作者返回的公開主頁屬性。
authorInfo.profile.isNsfw boolean 作者主頁是否帶有 NSFW 標記。
authorCommunityBadge object | null 評論作者的公開社區徽章,不可用時為 null。
authorCommunityBadge.accessibilityLabel string 社區徽章的無障礙文字標籤。
authorCommunityBadge.label string 社區徽章的展示文字。
authorCommunityBadge.image object 社區徽章圖片信息。
authorCommunityBadge.image.url string 社區徽章的公開圖片連結。
authorFlair object | null 評論作者返回的公開社區頭銜,不可用時為 null。
authorFlair.text string 作者社區頭銜的展示文字。
社區資料6 個欄位

data.postInfoById.subreddit

帖子所屬的公開社區資料。

欄位 類型 說明
id string Reddit 社區 ID。
name string Reddit 社區名稱。
prefixedName string 帶 Reddit 前綴的社區名稱。
isQuarantined boolean 社區是否標記為已隔離。
allowedMediaInComments array 社區允許在評論中使用的媒體類型。
allowedMediaInComments[] string 一種返回的評論可用媒體類型。

回應示例 ​

正在載入回應範例…