概述
Hacker News 通过跟我们 Firebase的合作,使得Hacker
News中的信息能够实时的公布给用户。你可以轻松的使用 Android, iOS 和
通过 web 访问Firebase提供的数据。从服务器端当然也可以。我们甚至还支持 REST 协议。
如果你能使用众多的 Firebase 客户端程序库 中的某个接口,那就应该优先使用它们。这些程序库能够高效的处理网络连接,在有事件发生时可以及时的通知你。你应该研究一下它们。
如果你发现了任何的bug,请邮件给我们 [email protected] 。
Hacker News API中的URI和版本
这些API都由https://hacker-news.firebaseio.com提供。
我们努力在不断的改进它,将来将会允许使用OAuth认证来访问每个用户的私人数据。这些API中的修改并不一定会向后兼容,所以,我们将API以版本号形式发布。我们的第一版的地址是 https://hacker-news.firebaseio.com/v0/,下面是对API的结构和用法的描述。
单个条目信息
故事,评论,招聘,问答,以及投票都叫做条目。它们有各自唯一的ID,是不相互重复的整数形式,接口地址是: https://hacker-news.firebaseio.com/v0/item/.
所有的条目都共有下面的属性:
属性 | 描述 |
---|---|
id | The item’s unique id. Required. |
deleted |
true ifthe item is deleted. |
type | The type of item. One of “job”, “story”, “comment”, “poll”, or “pollopt”. |
by | The username of the item’s author. |
time |
Creation date of the item, in Unix Time. |
text | The comment, Ask HN, or poll text. HTML. |
dead |
true ifthe item is dead. |
parent | The item’s parent. For comments, either another comment or the relevant story. For pollopts, the relevant poll. |
kids | The ids of the item’s comments, in ranked display order. |
url | The URL of the story. |
score | The story’s score, or the votes for a pollopt. |
title | The title of the story or poll. |
parts | A list of related pollopts, in display order. |
举例说明,一个故事的数据结构是这样的:: https://hacker-news.firebaseio.com/v0/item/8863.json?print=pretty
{ "by" : "dhouston", "id" : 8863, "kids" : [ 8952, 9224, 8917, 8884, 8887, 8943, 8869, 8958, 9005, 9671, 8940, 9067, 8908, 9055, 8865, 8881, 8872, 8873, 8955, 10403, 8903, 8928, 9125, 8998, 8901, 8902, 8907, 8894, 8878, 8870, 8980, 8934, 8876 ], "score" : 111, "time" : 1175714200, "title" : "My YC app: Dropbox - Throw away your USB drive", "type" : "story", "url" : "http://www.getdropbox.com/u/2/screencast.html" }
而评论的是: https://hacker-news.firebaseio.com/v0/item/2921983.json?print=pretty
{ "by" : "norvig", "id" : 2921983, "kids" : [ 2922097, 2922429, 2924562, 2922709, 2922573, 2922140, 2922141 ], "parent" : 2921506, "text" : "Aw shucks, guys ... you make me blush with your compliments.<p>Tell you what, Ill make a deal: I‘ll keep writing if you keep reading. K?", "time" : 1314211127, "type" : "comment" }
投票的是: https://hacker-news.firebaseio.com/v0/item/126809.json?print=pretty
{ "by" : "pg", "id" : 126809, "kids" : [ 126822, 126823, 126993, 126824, 126934, 127411, 126888, 127681, 126818, 126816, 126854, 127095, 126861, 127313, 127299, 126859, 126852, 126882, 126832, 127072, 127217, 126889, 127535, 126917, 126875 ], "parts" : [ 126810, 126811, 126812 ], "score" : 46, "text" : "", "time" : 1204403652, "title" : "Poll: What would happen if News.YC had explicit support for polls?", "type" : "poll" }
相关信息:https://hacker-news.firebaseio.com/v0/item/160705.json?print=pretty
{ "by" : "pg", "id" : 160705, "parent" : 160704, "score" : 335, "text" : "Yes, ban them; I‘m tired of seeing Valleywag stories on News.YC.", "time" : 1207886576, "type" : "pollopt" }
用户
用户的ID是区分大小写的,接口地址是 https://hacker-news.firebaseio.com/v0/user/.
属性 | 描述 |
---|---|
id | The user’s unique username. Case-sensitive. Required. |
delay | Delay in minutes between a comment’s creation and its visibility to other users. |
created |
Creation date of the user, in Unix Time. |
karma | The user’s karma. |
about | The user’s optional self-description. HTML. |
submitted | List of the user’s stories, polls and comments. |
举例说明: https://hacker-news.firebaseio.com/v0/user/jl.json?print=pretty
{ "about" : "This is a test", "created" : 1173923446, "delay" : 0, "id" : "jl", "karma" : 2937, "submitted" : [ 8265435, 8168423, 8090946, 8090326, 7699907, 7637962, 7596179, 7596163, 7594569, 7562135, 7562111, 7494708, 7494171, 7488093, 7444860, 7327817, 7280290, 7278694, 7097557, 7097546, 7097254, 7052857, 7039484, 6987273, 6649999, 6649706, 6629560, 6609127, 6327951, 6225810, 6111999, 5580079, 5112008, 4907948, 4901821, 4700469, 4678919, 3779193, 3711380, 3701405, 3627981, 3473004, 3473000, 3457006, 3422158, 3136701, 2943046, 2794646, 2482737, 2425640, 2411925, 2408077, 2407992, 2407940, 2278689, 2220295, 2144918, 2144852, 1875323, 1875295, 1857397, 1839737, 1809010, 1788048, 1780681, 1721745, 1676227, 1654023, 1651449, 1641019, 1631985, 1618759, 1522978, 1499641, 1441290, 1440993, 1436440, 1430510, 1430208, 1385525, 1384917, 1370453, 1346118, 1309968, 1305415, 1305037, 1276771, 1270981, 1233287, 1211456, 1210688, 1210682, 1194189, 1193914, 1191653, 1190766, 1190319, 1189925, 1188455, 1188177, 1185884, 1165649, 1164314, 1160048, 1159156, 1158865, 1150900, 1115326, 933897, 924482, 923918, 922804, 922280, 922168, 920332, 919803, 917871, 912867, 910426, 902506, 891171, 807902, 806254, 796618, 786286, 764412, 764325, 642566, 642564, 587821, 575744, 547504, 532055, 521067, 492164, 491979, 383935, 383933, 383930, 383927, 375462, 263479, 258389, 250751, 245140, 243472, 237445, 229393, 226797, 225536, 225483, 225426, 221084, 213940, 213342, 211238, 210099, 210007, 209913, 209908, 209904, 209903, 170904, 165850, 161566, 158388, 158305, 158294, 156235, 151097, 148566, 146948, 136968, 134656, 133455, 129765, 126740, 122101, 122100, 120867, 120492, 115999, 114492, 114304, 111730, 110980, 110451, 108420, 107165, 105150, 104735, 103188, 103187, 99902, 99282, 99122, 98972, 98417, 98416, 98231, 96007, 96005, 95623, 95487, 95475, 95471, 95467, 95326, 95322, 94952, 94681, 94679, 94678, 94420, 94419, 94393, 94149, 94008, 93490, 93489, 92944, 92247, 91713, 90162, 90091, 89844, 89678, 89498, 86953, 86109, 85244, 85195, 85194, 85193, 85192, 84955, 84629, 83902, 82918, 76393, 68677, 61565, 60542, 47745, 47744, 41098, 39153, 38678, 37741, 33469, 12897, 6746, 5252, 4752, 4586, 4289 ] }
实时数据
Firebase最酷的地方是支持实时数据更新通知。你可以订阅条目信息,这时你可以观察它们在首页的名次,那些新条目出现,或新的用户信息更新。
获取排名前100条信息
获取最新的排名前100条的API是这里: https://hacker-news.firebaseio.com/v0/topstories.
举例说明: https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty
[ 8414149, 8414078, 8413972, 8411638, 8414102, 8413204, 8413100, 8413971, 8412744, 8414003, 8412841, 8412802, 8412605, 8413548, 8413123, 8414437, 8412897, 8413028, 8413341, 8412425, 8411762, 8413623, 8412346, 8411356, 8413056, 8413365, 8412372, 8414055, 8412877, 8412167, 8413264, 8414137, 8410519, 8412933, 8411846, 8412929, 8411254, 8411512, 8412777, 8412626, 8413274, 8414389, 8414117, 8412114, 8412212, 8412759, 8412696, 8412768, 8411643, 8411866, 8413966, 8410976, 8410545, 8410358, 8413979, 8414129, 8411791, 8409075, 8410314, 8411532, 8411553, 8412099, 8412085, 8410356, 8409084, 8412862, 8409823, 8412705, 8410220, 8409323, 8414090, 8410326, 8414206, 8411026, 8408298, 8407364, 8413066, 8412104, 8412235, 8412786, 8395689, 8414318, 8406384, 8414314, 8406507, 8408501, 8413630, 8414180, 8400778, 8413804, 8407298, 8413233, 8412601, 8411277, 8409940, 8414287, 8397750, 8412679, 8412727, 8413104 ]
当前最大ID
获取当前最大ID的接口地址是 https://hacker-news.firebaseio.com/v0/maxitem.
举例说明: https://hacker-news.firebaseio.com/v0/maxitem.json?print=pretty
8423374
获取条目和用户的变更信息。
接口地址是这里: https://hacker-news.firebaseio.com/v0/updates.
例如:https://hacker-news.firebaseio.com/v0/updates.json?print=pretty
{ "items" : [ 8423305, 8420805, 8423379, 8422504, 8423178, 8423336, 8422717, 8417484, 8423378, 8423238, 8423353, 8422395, 8423072, 8423044, 8423344, 8423374, 8423015, 8422428, 8423377, 8420444, 8423300, 8422633, 8422599, 8422408, 8422928, 8394339, 8421900, 8420902, 8422087 ], "profiles" : [ "thefox", "mdda", "plinkplonk", "GBond", "rqebmm", "neom", "arram", "mcmancini", "metachris", "DubiousPusher", "dochtman", "kstrauser", "biren34", "foobarqux", "mkehrt", "nathanm412", "wmblaettler", "JoeAnzalone", "rcconf", "johndbritton", "msie", "cktsai", "27182818284", "kevinskii", "wildwood", "mcherm", "naiyt", "matthewmcg", "joelhaus", "tshtf", "MrZongle2", "Bogdanp" ] }
本文属翻译作品,英文原文标题是:Hacker News API。若无特别说明,英文原文及其衍生作品均使用知识共享署名-相同方式共享(Creative Commons)协议。您可以自由复制、散布、展示及演出本作品;若您改变、转变或更改本作品,仅在遵守与本作品相同的授权条款下,您才能散布由本作品产生的派生作品。