新時空 API

如需獲取更多信息或技術支持,請聯系:

contact@newtimespace.com

新時空 API 獲取單條或多條新聞詳情

方法: GET

路徑: /api/v1/news/:id

描述: 查詢指定新聞的詳情,支持多個 ID(逗號分隔)。

新闻项:

  • article_id: 字符串,文章 ID。
  • language: 字符串,語言代碼。
  • title: 字符串,標題。
  • description: 字符串,描述。
  • content: 字符串,正文。
  • tags: 字符串,標簽(逗號分隔)。
  • keywords: 數組,關鍵詞。
  • authors: 數組,作者。
  • category: 字符串,分類。
  • dataType: 字符串,常量 "news"。
  • url: 字符串,文章 URL。
  • pubDate: 字符串,發佈日期時間(Y-m-d H:i:s)。
  • pubDateTZ: 字符串,時區(UTC)。
  • date: 字符串,日期(Y-m-d)。
  • time: 字符串,時間(H:i:s)。
  • updated_at: 字符串,更新時間。
  • word_count: 整數,字數。
  • reading_time: 整數,閱讀時間(分鐘)。
  • is_breaking_news: 布爾,是否突發新聞。
  • sentiment: 字符串,情感(neutral 等)。
  • related_articles: 數組,相關文章。
  • geo_location: 字符串,地理位置。
  • source: 對象,來源信息(id, name, url, country, icon)。
  • image: 對象,圖片信息(url, alt, caption, source, credit)。
  • video: 對象,視頻信息(url, thumbnail, duration, source, credit)。

單條JSON響應示例
多條JSON相響應示例
錯誤響應(JSON 示例)
                         {
 "status": "success",
 "data": {
   "article_id": "123",
   "language": "zh-cn",
   "title": "新聞標題",
   "description": "新聞描述",
   "content": "新聞內容",
   "tags": "標簽1,標簽2",
   "keywords": ["關鍵詞1", "關鍵詞2"],
   "authors": ["作者1", "作者2"],
   "category": "分類名稱",
   "dataType": "news",
   "url": "https://www.newtimespace.com/zh-cn/article/123",
   "pubDate": "2026-01-13 12:00:00",
   "pubDateTZ": "UTC",
   "date": "2026-01-13",
   "time": "12:00:00",
   "updated_at": "2026-01-13 13:00:00",
   "word_count": 500,
   "reading_time": 3,
   "is_breaking_news": false,
   "sentiment": "neutral",
   "related_articles": [],
   "geo_location": "",
   "source": {
     "id": "",
     "name": "NewTimeSpace",
     "url": "",
     "country": "",
   "icon": ""
   },
   "image": {
     "url": "",
     "alt": "",
     "caption": "",
     "source": "",
     "credit": ""
   },
   "video": {
     "url": null,
     "thumbnail": "",
     "duration": "",
     "source": "",
     "credit": ""
   }
  }
 },
 "pagination": {
   "page": 1,
   "limit": 10,
   "total": 100,
   "pages": 10
  }
 }
                        
                      

參數 arrow

參數 類型 必填 描述 默認值
articleIds string 文章 ID(逗號分隔,如 "123,456")。 ''
language string 語言(zh-cn, zh-hk, en) zh-cn
format string 返回格式(json 或 xml) json

狀態碼 arrow

  • 200: 成功。
  • 400: 參數無效。
  • 404: 新聞未找到。
  • 500: 內部錯誤。

錯誤處理 arrow

  • API 使用標準 HTTP 狀態碼。
  • 錯誤響應包含 "status": "error" 和 "message" 字段(JSON)。
  • XML 錯誤:錯誤消息

附加信息 arrow

  • 日誌:錯誤記錄到系統日誌(Log::write)。
  • 緩存:分類信息使用靜態緩存。
  • 語言轉換:對於 zh-hk,使用簡繁轉換(需 Chinese 庫)。
  • 安全:參數過濾(intval, trim, addslashes)。
  • 依賴:ThinkPHP 框架,數據庫表(ts_information_news 等)。