跳至主要內容

Twitter帖子詳情 API (V1) ​

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

獲取由推文 ID 標識的 X(Twitter)帖子的完整詳情。在通過搜索、用戶時間線或現有帖子 URL 找到已知帖子後,使用此接口檢查該帖子。

請求參數 ​

參數名 位置 類型 必填 預設值 說明
token query string 是 - 訪問API所需的鑑權令牌。
tweetId query string 是 - X (Twitter) 帖子的唯一標識符。

程式碼範例 ​

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

請求參數說明:
- token (query): 訪問API所需的鑑權令牌。 (必填)
- tweetId (query): X (Twitter) 帖子的唯一標識符。 (必填)

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

帖子信息7 個欄位

data

欄位 類型 說明
id string X 帖子 ID,以字符串返回。
status string 回應資料中返回的狀態標識。
created_at string 帖子的發佈時間。
text string 帖子的正文。
display_text string 帖子用於展示的正文文本。
lang string Reddit 返回的帖子語言代碼。
sensitive boolean | null 有值時,表示帖子是否標記為可能包含敏感內容。
互動資料6 個欄位

data

欄位 類型 說明
likes integer 返回的點贊數。
retweets integer 返回的轉發數。
bookmarks integer 返回的書籤數。
quotes integer 返回的引用數。
replies integer 返回的回覆數。
views string 返回的瀏覽量,以數字字符串表示。
回覆關係5 個欄位

data

欄位 類型 說明
conversation_id string 對話中根帖子的 ID,以字符串返回。
reply_to string | null 直接回復的帖子 ID,存在時返回。
in_reply_to_status_id_str string | null 這條記錄直接回復的帖子 ID,以字符串返回。
in_reply_to_user_id_str string | null 這條記錄直接回復的帳號 ID,以字符串返回。
in_reply_to_screen_name string | null 這條記錄直接回復的帳號用戶名。
作者7 個欄位

data.author

這條帖子的作者公開資料。

欄位 類型 說明
rest_id string X 帳號 ID,以字符串返回。
name string 帳號的展示名稱。
screen_name string 帳號用戶名,不含 @ 前綴。
image string 用戶資料的頭像地址。
blue_verified boolean 返回的帳號藍勾標記。
verification string | null 返回的作者認證類別,存在時返回。
sub_count integer 返回的作者關注者數量。
連結與提及46 個欄位

data.entities

帖子正文中關聯的連結、提及等實體。

欄位 類型 說明
media array 帖子返回的媒體連結實體。
media[] object -
media[].id_str string 媒體連結實體的 ID,以字符串返回。
media[].type string 返回的媒體附件類型。
media[].media_url_https string 媒體連結實體關聯的 HTTPS 地址。
media[].original_info object 媒體附件的原始尺寸。
media[].original_info.height integer 原始媒體高度,單位為像素。
media[].original_info.width integer 原始媒體寬度,單位為像素。
media[].ext_media_availability object 媒體附件的可用性信息。
media[].ext_media_availability.status string 媒體附件返回的可用狀態。
media[].sizes object 媒體圖片的可用尺寸。
media[].sizes.large object 該尺寸版本的圖片尺寸。
media[].sizes.large.w integer 圖片寬度,單位為像素。
media[].sizes.large.h integer 圖片高度,單位為像素。
media[].sizes.large.resize string 該尺寸版本的縮放模式。
media[].sizes.medium object 該尺寸版本的圖片尺寸。
media[].sizes.medium.w integer 圖片寬度,單位為像素。
media[].sizes.medium.h integer 圖片高度,單位為像素。
media[].sizes.medium.resize string 該尺寸版本的縮放模式。
media[].sizes.small object 該尺寸版本的圖片尺寸。
media[].sizes.small.w integer 圖片寬度,單位為像素。
media[].sizes.small.h integer 圖片高度,單位為像素。
media[].sizes.small.resize string 該尺寸版本的縮放模式。
media[].sizes.thumb object 該尺寸版本的圖片尺寸。
media[].sizes.thumb.w integer 圖片寬度,單位為像素。
media[].sizes.thumb.h integer 圖片高度,單位為像素。
media[].sizes.thumb.resize string 該尺寸版本的縮放模式。
media[].video_info object 視頻實體附帶的播放信息。
media[].video_info.duration_millis integer 視頻時長,單位為毫秒。
media[].video_info.aspect_ratio array 視頻寬高比,由兩個整數組成。
media[].video_info.aspect_ratio[] integer -
media[].video_info.variants array 可用的視頻播放版本。
media[].video_info.variants[] object -
media[].video_info.variants[].url string 該視頻版本的播放地址。
media[].video_info.variants[].content_type string 該視頻版本的媒體類型。
media[].video_info.variants[].bitrate integer 該視頻版本返回的比特率。
urls array 帖子正文中的連結。
user_mentions array 帖子提及的帳號。
user_mentions[] object -
user_mentions[].id_str string X 帳號 ID,以字符串返回。
user_mentions[].name string 帳號的展示名稱。
user_mentions[].screen_name string 帳號用戶名,不含 @ 前綴。
user_mentions[].indices array 實體在帖子正文中的起止位置。
user_mentions[].indices[] integer -
hashtags array 帖子返回的話題標籤實體。
symbols array 帖子返回的符號標籤實體。
圖片與視頻19 個欄位

data.media

帖子返回的媒體附件。

欄位 類型 說明
photo array 帖子附帶的圖片。
photo[] object -
photo[].id string 圖片附件的 ID,以字符串返回。
photo[].media_url_https string 圖片的 HTTPS 地址。
video array 帖子附帶的視頻。
video[] object -
video[].id string 視頻附件的 ID,以字符串返回。
video[].media_url_https string 視頻預覽圖的 HTTPS 地址。
video[].original_info object 媒體附件的原始尺寸。
video[].original_info.height integer 原始媒體高度,單位為像素。
video[].original_info.width integer 原始媒體寬度,單位為像素。
video[].aspect_ratio array 視頻寬高比,由兩個整數組成。
video[].aspect_ratio[] integer -
video[].duration integer 視頻時長,單位為毫秒。
video[].variants array 可用的視頻播放版本。
video[].variants[] object -
video[].variants[].url string 該視頻版本的播放地址。
video[].variants[].content_type string 該視頻版本的媒體類型。
video[].variants[].bitrate integer 該視頻版本返回的比特率。
引用與連結卡片23 個欄位

data

欄位 類型 說明
quoted object 這條記錄引用的帖子,存在時返回。
quoted.tweet_id string X 帖子 ID,以字符串返回。
quoted.created_at string 帖子的發佈時間。
quoted.text string 帖子的正文。
quoted.lang string Reddit 返回的帖子語言代碼。
quoted.conversation_id string 對話中根帖子的 ID,以字符串返回。
quoted.favorites integer 返回的點贊數。
quoted.retweets integer 返回的轉發數。
quoted.bookmarks integer 返回的書籤數。
quoted.quotes integer 返回的引用數。
quoted.replies integer 返回的回覆數。
quoted.views string 返回的瀏覽量,以數字字符串表示。
quoted.author object 這條帖子的作者公開資料。
quoted.author.rest_id string X 帳號 ID,以字符串返回。
quoted.author.name string 帳號的展示名稱。
quoted.author.screen_name string 帳號用戶名,不含 @ 前綴。
quoted.author.avatar string 用戶資料的頭像地址。
quoted.author.blue_verified boolean 返回的帳號藍勾標記。
quoted.media array 帖子返回的媒體附件。
card object 帖子返回的連結預覽卡片,存在時返回。
card.type string 連結預覽卡片的類型標識。
card.url string 連結卡片關聯的目標地址。
card.media object 連結卡片關聯的預覽媒體。

回應示例 ​

正在載入回應範例…