知乎日報 API 分析
聲明
下面全部 API 均由 知乎(Zhihu.Inc) 提供,本人採取非正常手段獲取。
獲取與共享之行為或有侵犯知乎權益的嫌疑。若被告知需停止共享與使用。本人會及時刪除此頁面與整個項目。
請您暸解相關情況。並遵守知乎協議。
API 說明
-
知乎日報的消息以 JSON 格式輸出
-
網址中
api
後數字代表 API 版本號,過高或過低均會得到錯誤信息 -
較老的接口(啟動界面圖像獲取。最新消息,過往消息)中將數字 2 替換為 1.2 獲得效果同樣。替換為 1.1 獲得的是老版本號 API 輸出的 JSON 格式(替換為更低,如 1.0,或更高。如 1.3,將會獲得錯誤消息)
-
下面全部 API 使用的 HTTP Method 均為
GET
API 分析
1. 啟動界面圖像獲取
- URL:
http://news-at.zhihu.com/api/4/start-image/1080*1776
-
start-image
後為圖像分辨率,接受例如以下格式320*432
480*728
720*1184
1080*1776
-
響應實例:
{ text: "? Fido Dido", img: "http://p2.zhimg.com/10/7b/107bb4894b46d75a892da6fa80ef504a.jpg" }
-
分析:
text
: 供顯示的圖片版權信息img
: 圖像的 URL
2. 軟件版本號查詢
- Android:
http://news-at.zhihu.com/api/4/version/android/2.3.0
- iOS:
http://news-at.zhihu.com/api/4/version/ios/2.3.0
- URL 最後部分的數字代表所安裝『知乎日報』的版本號
-
響應實例:
軟件為最新版本號時
{ "status": 0, "latest": "2.2.0" }
軟件為較老版本號時
{ "status": 1, "msg": "【更新內容】(後略)", "latest": "2.2.0" }
-
分析:
status
: 0 代表軟件為最新版本號,1 代表軟件須要升級latest
: 軟件最新版本號的版本號號(數字的第二段會比最新的版本號號低 1)msg
: 僅出如今軟件須要升級的情形下。提示用戶升級軟件的對話框中顯示的消息
3. 最新消息
- URL:
http://news-at.zhihu.com/api/4/news/latest
-
響應實例:
{ date: "20140523", stories: [ { title: "中國古代家具發展到今天有兩個高峰,一個兩宋一個明末(多圖)", ga_prefix: "052321", images: [ "http://p1.zhimg.com/45/b9/45b9f057fc1957ed2c946814342c0f02.jpg" ], type: 0, id: 3930445 }, ... ], top_stories: [ { title: "商場和非常多人家裏。竹制家具越來越多(多圖)", image: "http://p2.zhimg.com/9a/15/9a1570bb9e5fa53ae9fb9269a56ee019.jpg", ga_prefix: "052315", type: 0, id: 3930883 }, ... ] }
-
分析:
date
: 日期stories
: 當日新聞title
: 新聞標題images
: 圖像地址(官方 API 使用數組形式。眼下暫未有使用多張圖片的情形出現,曾見無
images
屬性的情況,請在使用中註意 )ga_prefix
: 供 Google Analytics 使用type
: 作用未知id
:url
與share_url
中最後的數字(應為內容的 id)multipic
: 消息是否包括多張圖片(僅出如今包括多圖的新聞中)
top_stories
: 界面頂部 ViewPager 滾動顯示的顯示內容(子項格式同上)
4. 消息內容獲取與離線下載
- URL:
http://news-at.zhihu.com/api/4/news/3892357
- 使用在
最新消息
中獲得的id
,拼接在http://news-at.zhihu.com/api/4/news/
後,得到相應消息 JSON 格式的內容 -
響應實例:
{ body: "<div class="main-wrap content-wrap">...</div>", image_source: "Yestone.com 版權圖片庫", title: "深夜驚奇 · 朋友圈錯覺", image: "http://pic3.zhimg.com/2d41a1d1ebf37fb699795e78db76b5c2.jpg", share_url: "http://daily.zhihu.com/story/4772126", js: [ ], recommenders": [ { "avatar": "http://pic2.zhimg.com/fcb7039c1_m.jpg" }, { "avatar": "http://pic1.zhimg.com/29191527c_m.jpg" }, { "avatar": "http://pic4.zhimg.com/e6637a38d22475432c76e6c9e46336fb_m.jpg" }, { "avatar": "http://pic1.zhimg.com/bd751e76463e94aa10c7ed2529738314_m.jpg" }, { "avatar": "http://pic1.zhimg.com/4766e0648_m.jpg" } ], ga_prefix: "050615", section": { "thumbnail": "http://pic4.zhimg.com/6a1ddebda9e8899811c4c169b92c35b3.jpg", "id": 1, "name": "深夜驚奇" }, type: 0, id: 4772126, css: [ "http://news.at.zhihu.com/css/news_qa.auto.css?v=1edab" ] }
-
分析:
body
: HTML 格式的新聞image-source
: 圖片的內容提供方。為了避免被起訴非法使用圖片,在顯示圖片時最好附上其版權信息。title
: 新聞標題image
: 獲得的圖片同最新消息
獲得的圖片分辨率不同。這裏獲得的是在文章瀏覽界面中使用的大圖。share_url
: 供在線查看內容與分享至 SNS 用的 URLjs
: 供手機端的 WebView(UIWebView) 使用recommenders
: 這篇文章的推薦者ga_prefix
: 供 Google Analytics 使用section
: 欄目的信息thumbnail
: 欄目的縮略圖id
: 該欄目的id
name
: 該欄目的名稱
type
: 新聞的類型id
: 新聞的 idcss
: 供手機端的 WebView(UIWebView) 使用- 可知,知乎日報的文章瀏覽界面利用 WebView(UIWebView) 實現
-
特別註意
在較為特殊的情況下。知乎日報可能將某個主題日報的站外文章推送至知乎日報首頁。
響應實例:{ "theme_name": "電影日報", "title": "五分鐘讀懂明星的花樣昵稱:一美、法鯊……", "share_url": "http://daily.zhihu.com/story/3942319", "js": [], "ga_prefix": "052921", "editor_name": "鄒波", "theme_id": 3, "type": 1, "id": 3942319, "css": [ "http://news.at.zhihu.com/css/news_qa.6.css?
v=b390f" ] }
此時返回的 JSON 數據缺少
body
。image-source
,image
,js
屬性。多出
theme_name
。editor_name
,theme_id
三個屬性。type
由0
變為1
。
5. 過往消息
- URL:
http://news.at.zhihu.com/api/4/news/before/20131119
- 若果須要查詢 11 月 18 日的消息,
before
後的數字應為20131119
- 知乎日報的生日為 2013 年 5 月 19 日,若
before
後數字小於20130520
,僅僅會接收到空消息
- 輸入的今日之後的日期仍然獲得今日內容,可是格式不同於最新消息的 JSON 格式
-
響應實例:
{ date: "20131118", stories: [ { title: "深夜食堂 · 我的張曼妮", ga_prefix: "111822", images: [ "http://p4.zhimg.com/7b/c8/7bc8ef5947b069513c51e4b9521b5c82.jpg" ], type: 0, id: 1747159 }, ... ] }
-
格式與前同。恕不再贅述
6. 新聞額外信息
- URL:
http://news-at.zhihu.com/api/4/story-extra/#{id}
- 輸入新聞的ID。獲取相應新聞的額外信息,如評論數量,所獲的『贊』的數量。
-
響應實例:
{ "long_comments": 0, "popularity": 161, "short_comments": 19, "comments": 19, }
-
分析:
long_comments
: 長評論總數popularity
: 點贊總數short_comments
: 短評論總數comments
: 評論總數
7. 新聞相應長評論查看
- URL:
http://news-at.zhihu.com/api/4/story/4232852/long-comments
- 使用在
最新消息
中獲得的id
,在http://news-at.zhihu.com/api/4/story/#{id}/long-comments
中將id
替換為相應的id
,得到長評論 JSON 格式的內容 -
響應實例:
{ "comments": [ { "author": "EleganceWorld", "id": 545442, "content": "上海到濟南。無盡的豬排蓋飯… (後略)", "likes": 0, "time": 1413589303, "avatar": "http://pic2.zhimg.com/1f76e6a25_im.jpg" }, ... ] }
-
分析:
comments
: 長評論列表,形式為數組(請註意,其長度可能為 0)author
: 評論作者id
: 評論者的唯一標識符content
: 評論的內容likes
: 評論所獲『贊』的數量time
: 評論時間avatar
: 用戶頭像圖片的地址
8. 新聞相應短評論查看
- URL:
http://news-at.zhihu.com/api/4/story/4232852/short-comments
- 使用在
最新消息
中獲得的id
。在http://news-at.zhihu.com/api/4/story/#{id}/short-comments
中將id
替換為相應的id
。得到短評論 JSON 格式的內容 -
響應實例:
{ "comments": [ { "author": "Xiaole說", "id": 545721, "content": "就吃了個花生米,呵呵", "likes": 0, "time": 1413600071, "avatar": "http://pic1.zhimg.com/c41f035ab_im.jpg" }, ... ] }
-
格式與前同,恕不再贅述
9. 主題日報列表查看
- URL:
http://news-at.zhihu.com/api/4/themes
-
響應實例:
{ "limit": 1000, "subscribed": [ ], "others": [ { "color": 8307764, "thumbnail": "http://pic4.zhimg.com/2c38a96e84b5cc8331a901920a87ea71.jpg", "description": "內容由知乎用戶推薦,海納主題百萬,趣味上天入地", "id": 12, "name": "用戶推薦日報" }, ... ] }
- 分析:
limit
: 返回數目之限制(僅為推測)subscribed
: 已訂閱條目others
: 其它條目color
: 顏色,作用未知thumbnail
: 供顯示的圖片地址description
: 主題日報的介紹id
: 該主題日報的編號name
: 供顯示的主題日報名稱
- 分析:
10. 主題日報內容查看
- URL:
http://news-at.zhihu.com/api/4/theme/11
- 使用在
主題日報列表查看
中獲得須要查看的主題日報的id
。拼接在http://news-at.zhihu.com/api/4/theme/
後,得到相應主題日報 JSON 格式的內容 -
響應實例:
{ stories: [ { images: [ "http://pic1.zhimg.com/84dadf360399e0de406c133153fc4ab8_t.jpg" ], type: 0, id: 4239728, title: "前蘇聯監獄紋身百科圖鑒" }, ... ], description: "為你發現最有趣的新奇事,建議在 WiFi 下查看", background: "http://pic1.zhimg.com/a5128188ed788005ad50840a42079c41.jpg", color: 8307764, name: "不許無聊", image: "http://pic3.zhimg.com/da1fcaf6a02d1223d130d5b106e828b9.jpg", editors: [ { url: "http://www.zhihu.com/people/wezeit", bio: "微在 Wezeit 主編", id: 70, avatar: "http://pic4.zhimg.com/068311926_m.jpg", name: "益康糯米" }, ... ], image_source: "" }
- 分析:
stories
: 該主題日報中的文章列表images
: 圖像地址(其類型為數組。請留意在代碼中處理無該屬性與數組長度為 0 的情況)type
: 類型,作用未知title
: 消息的標題
description
: 該主題日報的介紹background
: 該主題日報的背景圖片(大圖)color
: 顏色,作用未知name
: 該主題日報的名稱image
: 背景圖片的小圖版本號editors
: 該主題日報的編輯(『用戶推薦日報』中此項的指是一個空數組。在 App 中的主編欄顯示為『很多人』,點擊後訪問該主題日報的介紹頁面,請留意)url
: 主編的知乎用戶主頁bio
: 主編的個人簡單介紹id
: 數據庫中的唯一表示符avatar
: 主編的頭像name
: 主編的姓名
image_source
: 圖像的版權信息
- 分析:
11. 熱門消息
- 請註意! 此 API 仍可訪問,可是其內容未出如今最新的『知乎日報』 App 中。
- URL:
http://news-at.zhihu.com/api/3/news/hot
-
響應實例:
{ recent: [ { news_id: 3748552, url: "http://daily.zhihu.com/api/2/news/3748552", thumbnail: "http://p3.zhimg.com/67/6a/676a8337efec71a100eea6130482091b.jpg", title: "長得美麗能力出眾性格單純的姑娘為什麽會沒有男朋友?" }, ... ] }
-
大體同前面介紹的 API 類似,唯一須要註意的是:欲獲得圖片地址。不再使用
image
而是thumbnail
屬性 url
屬性可直接使用。請註意,url
中的api
屬性為 2,是較老版本號。
12. 軟件推廣
- 請註意。 此 API 已無法訪問,可是其內容曾出現於『知乎日報』 App 中。
- Android:
http://news-at.zhihu.com/api/3/promotion/android
- iOS:
http://news-at.zhihu.com/api/3/promotion/ios
13. 欄目總覽
- 請註意! 此 API 仍可訪問。可是其內容未出如今最新的『知乎日報』 App 中。
- URL:
http://news-at.zhihu.com/api/3/sections
-
響應實例:
{ data: [ { id: 1, thumbnail: "http://p2.zhimg.com/10/b8/10b8193dd6a3404d31b2c50e1e232c87.jpg", name: "深夜食堂", description: "睡前宵夜,用別人的故事下酒" }, ... ] }
-
相同,註意使用
thumbnail
獲取圖像的地址
14. 欄目詳細消息查看
- 請註意! 此 API 仍可訪問,可是其內容未出如今最新的『知乎日報』 App 中。
- URL:
http://news-at.zhihu.com/api/3/section/1
- URL 最後的數字見『欄目總覽』中對應欄目的
id
屬性 -
響應實例:
{ news: [ { date: "20140522", display_date: "5 月 22 日" }, ... ], name: "深夜食堂", timestamp: 1398780001 }
-
往前:
http://news-at.zhihu.com/api/3/section/1/before/1398780001
- 在 URL 最後加上一個時間戳,時間戳詳見 JSON 數據末端的
timestamp
屬性
- 在 URL 最後加上一個時間戳,時間戳詳見 JSON 數據末端的
15. 查看新聞的推薦者
- URL:
http://news-at.zhihu.com/api/4/story/#{id}/recommenders
- 將新聞id填入到#{id}的位置。 如
http://news-at.zhihu.com/api/4/story/7101963/recommenders
-
響應實例
{ "items": [], "editors": [{ "bio": "樹上的女爵", "title": "主編", "id": 79, "avatar": "http:\/\/pic1.zhimg.com\/0a6456810_m.jpg", "name": "劉柯" }], "item_count": 1 }
16. 獲取某個專欄之前的新聞
- URL:
http://news-at.zhihu.com/api/4/theme/#{theme id}/before/#{id}
- 將專欄id填入到 #{theme id}, 將新聞id填入到#{id},如
http://news-at.zhihu.com/api/4/theme/11/before/7119483
- 註:新聞id要是屬於該專欄,否則。返回結果為空
-
響應實例:
{ "stories": [ { "images": [ "http://pic2.zhimg.com/27f3d8f4c1e0000d04ee446a2f020cf1_t.jpg" ], "type": 2, "id": 7119477, "title": "9 張本周最熱節操圖。諾一就是人生贏家本人" }, ... ] }
17. 查看editor的主頁
- iOS:
http://news-at.zhihu.com/api/4/editor/#{id}/profile-page/ios
- Android:
http://news-at.zhihu.com/api/4/editor/#{id}/profile-page/android
- 如 http://news-at.zhihu.com/api/4/editor/79/profile-page/ios
知乎日報 API 分析