https://github.com/izzyleung/ZhihuDailyPurify/wiki/%E7%9F%A5%E4%B9%8E%E6%97%A5%E6%8A%A5-API-%E5%88%86%E6%9E%90
聲明
以下所有 API 均由知乎(Zhihu.Inc)提供捣卤,本人(Xiao Liang)采取非正常手段獲取。獲取與共享之行為或有侵犯知乎權(quán)益的嫌疑。若被告知需停止共享與使用峦耘,本人會及時刪除此頁面與整個項目按傅。
請您暸解相關(guān)情況撰筷,并遵守知乎協(xié)議茂蚓。
知乎日報的消息以 JSON 格式輸出
網(wǎng)址中api后數(shù)字代表 API 版本胸懈,過高或過低均會得到錯誤信息
較老的接口(啟動界面圖像獲取交汤,最新消息雏赦,過往消息)中將數(shù)字 2 替換為 1.2 獲得效果相同,替換為 1.1 獲得的是老版本 API 輸出的 JSON 格式(替換為更低,如 1.0星岗,或更高填大,如 1.3,將會獲得錯誤消息)
以下所有 API 使用的 HTTP Method 均為GET
URL:http://news-at.zhihu.com/api/4/start-image/1080*1776
start-image后為圖像分辨率俏橘,接受任意的number*number格式允华,number為任意非負整數(shù),返回值均相同寥掐。
響應實例:
{
text: "? Fido Dido",
img: "http://p2.zhimg.com/10/7b/107bb4894b46d75a892da6fa80ef504a.jpg"
}
分析:
text: 供顯示的圖片版權(quán)信息
img: 圖像的 URL
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 最后部分的數(shù)字代表所安裝『知乎日報』的版本
響應實例:
軟件為最新版本時
{
"status": 0,
"latest": "2.2.0"
}
軟件為較老版本時
{
"status": 1,
"msg": "【更新內(nèi)容】(后略)",
"latest": "2.2.0"
}
分析:
status: 0 代表軟件為最新版本靴寂,1 代表軟件需要升級
latest: 軟件最新版本的版本號(數(shù)字的第二段會比最新的版本號低 1)
msg: 僅出現(xiàn)在軟件需要升級的情形下,提示用戶升級軟件的對話框中顯示的消息
URL:http://news-at.zhihu.com/api/4/news/latest
響應實例:
{
date: "20140523",
stories: [
{
title: "中國古代家具發(fā)展到今天有兩個高峰曹仗,一個兩宋一個明末(多圖)",
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 使用數(shù)組形式。目前暫未有使用多張圖片的情形出現(xiàn)怎茫,曾見無images屬性的情況收壕,請在使用中注意 )
ga_prefix: 供 Google Analytics 使用
type: 作用未知
id:url與share_url中最后的數(shù)字(應為內(nèi)容的 id)
multipic: 消息是否包含多張圖片(僅出現(xiàn)在包含多圖的新聞中)
top_stories: 界面頂部 ViewPager 滾動顯示的顯示內(nèi)容(子項格式同上)(請注意區(qū)分此處的image屬性與stories中的images屬性)
URL:http://news-at.zhihu.com/api/4/news/3892357
使用在最新消息中獲得的id,拼接在http://news-at.zhihu.com/api/4/news/后轨蛤,得到對應消息 JSON 格式的內(nèi)容
響應實例:
{
body: "
image_source: "Yestone.com 版權(quán)圖片庫",
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: 圖片的內(nèi)容提供方蜜宪。為了避免被起訴非法使用圖片,在顯示圖片時最好附上其版權(quán)信息祥山。
title: 新聞標題
image: 獲得的圖片同最新消息獲得的圖片分辨率不同圃验。這里獲得的是在文章瀏覽界面中使用的大圖。
share_url: 供在線查看內(nèi)容與分享至 SNS 用的 URL
js: 供手機端的 WebView(UIWebView) 使用
recommenders: 這篇文章的推薦者
ga_prefix: 供 Google Analytics 使用
section: 欄目的信息
thumbnail: 欄目的縮略圖
id: 該欄目的id
name: 該欄目的名稱
type: 新聞的類型
id: 新聞的 id
css: 供手機端的 WebView(UIWebView) 使用
可知缝呕,知乎日報的文章瀏覽界面利用 WebView(UIWebView) 實現(xiàn)
特別注意
在較為特殊的情況下澳窑,知乎日報可能將某個主題日報的站外文章推送至知乎日報首頁。
響應實例:
{
"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 數(shù)據(jù)缺少body摊聋,image-source,image栈暇,js屬性麻裁。多出theme_name,editor_name源祈,theme_id三個屬性煎源。type由0變?yōu)?。
URL:http://news.at.zhihu.com/api/4/news/before/20131119
若果需要查詢 11 月 18 日的消息香缺,before后的數(shù)字應為20131119
知乎日報的生日為 2013 年 5 月 19 日手销,若before后數(shù)字小于20130520,只會接收到空消息
輸入的今日之后的日期仍然獲得今日內(nèi)容图张,但是格式不同于最新消息的 JSON 格式
響應實例:
{
date: "20131118",
stories: [
{
title: "深夜食堂 · 我的張曼妮",
ga_prefix: "111822",
images: [
"http://p4.zhimg.com/7b/c8/7bc8ef5947b069513c51e4b9521b5c82.jpg"
],
type: 0,
id: 1747159
},
...
]
}
格式與前同原献,恕不再贅述
URL:http://news-at.zhihu.com/api/4/story-extra/#{id}
輸入新聞的ID馏慨,獲取對應新聞的額外信息,如評論數(shù)量姑隅,所獲的『贊』的數(shù)量。
響應實例:
{
"long_comments": 0,
"popularity": 161,
"short_comments": 19,
"comments": 19,
}
分析:
long_comments: 長評論總數(shù)
popularity: 點贊總數(shù)
short_comments: 短評論總數(shù)
comments: 評論總數(shù)
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 格式的內(nèi)容
響應實例:
{
"comments": [
{
"author": "EleganceWorld",
"id": 545442,
"content": "上海到濟南,無盡的豬排蓋飯… (后略)",
"likes": 0,
"time": 1413589303,
"avatar": "http://pic2.zhimg.com/1f76e6a25_im.jpg"
},
...
]
}
分析:
comments: 長評論列表痪蝇,形式為數(shù)組(請注意鄙陡,其長度可能為 0)
author: 評論作者
id: 評論者的唯一標識符
content: 評論的內(nèi)容
likes: 評論所獲『贊』的數(shù)量
time: 評論時間
avatar: 用戶頭像圖片的地址
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 格式的內(nèi)容
響應實例:
{
"comments": [
{
"author": "Xiaole說",
"id": 545721,
"content": "就吃了個花生米趁矾,呵呵",
"likes": 0,
"time": 1413600071,
"avatar": "http://pic1.zhimg.com/c41f035ab_im.jpg"
},
...
]
}
格式與前同,恕不再贅述
URL:http://news-at.zhihu.com/api/4/themes
響應實例:
{
"limit": 1000,
"subscribed": [ ],
"others": [
{
"color": 8307764,
"thumbnail": "http://pic4.zhimg.com/2c38a96e84b5cc8331a901920a87ea71.jpg",
"description": "內(nèi)容由知乎用戶推薦给僵,海納主題百萬毫捣,趣味上天入地",
"id": 12,
"name": "用戶推薦日報"
},
...
]
}
分析:
limit: 返回數(shù)目之限制(僅為猜測)
subscribed: 已訂閱條目
others: 其他條目
color: 顏色,作用未知
thumbnail: 供顯示的圖片地址
description: 主題日報的介紹
id: 該主題日報的編號
name: 供顯示的主題日報名稱
URL:http://news-at.zhihu.com/api/4/theme/11
使用在主題日報列表查看中獲得需要查看的主題日報的id帝际,拼接在http://news-at.zhihu.com/api/4/theme/后蔓同,得到對應主題日報 JSON 格式的內(nèi)容
響應實例:
{
stories: [
{
images: [
"http://pic1.zhimg.com/84dadf360399e0de406c133153fc4ab8_t.jpg"
],
type: 0,
id: 4239728,
title: "前蘇聯(lián)監(jiān)獄紋身百科圖鑒"
},
...
],
description: "為你發(fā)現(xiàn)最有趣的新鮮事,建議在 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: 圖像地址(其類型為數(shù)組蹲诀。請留意在代碼中處理無該屬性與數(shù)組長度為 0 的情況)
type: 類型斑粱,作用未知
title: 消息的標題
description: 該主題日報的介紹
background: 該主題日報的背景圖片(大圖)
color: 顏色,作用未知
name: 該主題日報的名稱
image: 背景圖片的小圖版本
editors: 該主題日報的編輯(『用戶推薦日報』中此項的指是一個空數(shù)組脯爪,在 App 中的主編欄顯示為『許多人』则北,點擊后訪問該主題日報的介紹頁面,請留意)
url: 主編的知乎用戶主頁
bio: 主編的個人簡介
id: 數(shù)據(jù)庫中的唯一表示符
avatar: 主編的頭像
name: 主編的姓名
image_source: 圖像的版權(quán)信息
請注意痕慢!此 API 仍可訪問尚揣,但是其內(nèi)容未出現(xiàn)在最新的『知乎日報』 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,是較老版本俺叭。
請注意恭取!此 API 已無法訪問,但是其內(nèi)容曾出現(xiàn)于『知乎日報』 App 中熄守。
Android:http://news-at.zhihu.com/api/3/promotion/android
iOS:http://news-at.zhihu.com/api/3/promotion/ios
請注意蜈垮!此 API 仍可訪問耗跛,但是其內(nèi)容未出現(xiàn)在最新的『知乎日報』 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獲取圖像的地址
請注意!此 API 仍可訪問惠猿,但是其內(nèi)容未出現(xiàn)在最新的『知乎日報』 App 中羔砾。
URL:http://news-at.zhihu.com/api/3/section/1
URL 最后的數(shù)字見『欄目總覽』中相應欄目的id屬性
響應實例:
{
news: [
{
date: "20140522",
display_date: "5 月 22 日"
},
...
],
name: "深夜食堂",
timestamp: 1398780001
}
往前:http://news-at.zhihu.com/api/3/section/1/before/1398780001
在 URL 最后加上一個時間戳,時間戳詳見 JSON 數(shù)據(jù)末端的timestamp屬性
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
}
URL:http://news-at.zhihu.com/api/4/section/#{section id}/before/#{timestamp}
將專欄id填入到 #{section id}, 將時間戳填入到#{timestamp}姜凄,如http://news-at.zhihu.com/api/4/section/34/before/1465772400
注:新聞id要是屬于該專欄,否則趾访,返回結(jié)果為空
響應實例:
{
"stories": [
{
"images": [
"http://pic2.zhimg.com/27f3d8f4c1e0000d04ee446a2f020cf1_t.jpg"
],
"type": 2,
"id": 7119477,
"title": "9 張本周最熱節(jié)操圖态秧,諾一就是人生贏家本人"
}, ...
]
}
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