top | item 32540883

Hacker News Official API

500 points| marchupfield | 3 years ago |github.com

131 comments

order
[+] goranmoomin|3 years ago|reply
Only using the official API is quite cumbersome, as fetching a story with comments requires one network request per each comment.

Instead, try considering the (more unknown) Algolia API[0]. It supports fetching the entire tree in one request. Unfortunately the comments aren’t sorted, so you’ll still have to use the official one (or parse the HN HTML) if you need that.

For my HN client[1], I parse the HN HTML (as it’s required for voting), and sort the comments from the Algolia API. It’s much faster than recursively requesting the official API.

[0]: https://hn.algolia.com/api

[1]: https://github.com/goranmoomin/HackerNews

[+] CodesInChaos|3 years ago|reply
If you already parse the html, what's the point in calling the Algolia API at all?
[+] dang|3 years ago|reply
In response to people's complaints about the usability of the HN Firebase API: yes. We're going to eventually have a new API that returns a simple JSON version of any HN URL. At that point we'll phase out the Firebase API, with a generous deprecation period. I'd be curious to hear people's thoughts about what a generous deprecation period might be.
[+] somishere|3 years ago|reply
The great thing about the Firebase API is that it's live, so you can subscribe to updates to a post/comment/profile and see them as they're made (no polling, just websockets). I'd hope any future version would retain this feature.

I'm reluctant to lose it as I'm about to release a browser extension that relies on it pretty heavily :)

[Edit]: this feature is undocumented in the link above, but it's a standard feature of FB and works as expected in all client libraries https://firebase.google.com/docs/database

[+] MarcellusDrum|3 years ago|reply
I'd say it depends on how straightforward the new API will be. The app I use (Materialistic) is both free and ads-free. So I don't expect the developer to drop everything they are doing to update it if will require a lot of work. So 6 months minimum if everything is well documented, a year if it will be a hassle.
[+] arthurcolle|3 years ago|reply
I would say a full calendar year is "generous" from the announcement date
[+] catnip09|3 years ago|reply
Can you allow login and write operation via the API?

I want to build a HN web client but it's not possible without scrapping the site which won't scale.

[+] ksec|3 years ago|reply
6 to 12 months AFTER we have dark mode.
[+] krapp|3 years ago|reply
Honestly, it would be nice if the Firebase API were updated. You could even build the former on the latter, so JSON urls pull from the API.

Just being able to get an entire thread in a single request alone, and filter queries would make things much easier.

[+] saagarjha|3 years ago|reply
How difficult would it be to host the same Firebase API on top of whatever will be driving the new JSON stuff?
[+] livinglist|3 years ago|reply
As a dev who has built a Hacker News client app, I would say at least 12 months.
[+] O__________O|3 years ago|reply
Wish API would show comment votes instead of only showing them up until 8 years ago when displaying them was turned off on the main site. Aside from allowing users to enable them via their on interface, do analysis, etc — it broke HN’s comment search based on comment popularity.

Related:

https://news.ycombinator.com/item?id=32535637

[+] chrismorgan|3 years ago|reply
I’d like to be able to conveniently access my most popular comments. There are quite a few things in there that I might like to write longer-form articles about.

(https://james.darpinian.com/blog/scraping-my-own-hacker-news... gives one way of doing it, by crawling your /threads?id=‹username› page, which does contain the point counts for each comment by you.)

[+] 1123581321|3 years ago|reply
I don’t want vote information to be publicly available. Hiding those numbers was good for the site. Users have ways to get their own data. That’s enough.
[+] metadat|3 years ago|reply
What difference would exposing counts make? Why should this data be mineable?

We're already helping to create a training set of slightly above average English speaker discourse for free.

[+] AtroxDev|3 years ago|reply
I found the official API quite a pain to work with while building myself an alternative "hn ui"[0]. I mostly switched over to using the Algolia API[1], which is a lot more "fun" to work with. I can only recommend checking that one out as well.

[0]: https://hnhub.dev/

[1]: https://hn.algolia.com/api/

[+] avg_dev|3 years ago|reply
I wrote a fairly simple "Who is hiring?" browser (using this API) that fetched the post listings and stored them locally in an HTML file accessible by pointing your browser at file:///... . It supported filtering by "Remote", "Interns", and "Visa" with buttons, had an ad hoc Regex filter, and the ability to remove posts using a delete button and not see them again (or to restore all deleted posts) using the localStorage api.

It was indeed barebones but I'd like to think it helped me find a job. I would link the code (it's on GitHub) but today the "Who is hiring?" posts include a few considerably more advanced and capable "searchers" right in the top of the post:

> Searchers: try https://kennytilton.github.io/whoishiring/, https://hnjobs.emilburzo.com, https://news.ycombinator.com/item?id=10313519.

It was fun; I enjoyed working on it.

[+] maxique|3 years ago|reply
I'd still like to see yours if you're up to sharing! :)
[+] reneberlin|3 years ago|reply
Firebase is owned by google. There are plenty of OSS solutions to create this exact realtime thing without getting too close to the elephant in the room.
[+] easrng|3 years ago|reply
I don't think it was owned by google when hn started using it for the API.
[+] greatgib|3 years ago|reply
This is so awesome. I like very much the spirit of giving access to the api as-is. With no fuss.
[+] Asdrubalini|3 years ago|reply
I'm currently writing an HN posts score tracker (basically it plots score variations over time since they were in new for each popular post) and it's really handy that you can just subscribe with eventsource [0] and get realtime update when something changes without having to manually poll each post wasting resources. Not yet sure about the latency though.

[0] https://github.com/jpopesculian/reqwest-eventsource/

[+] BeyondSchwifty|3 years ago|reply
Anyone know of a good tool to get something like push notifications when specific topics come up on HN? I've been thinking maybe I should build one, but I also feel like someone must have already done it by now.
[+] mavci|3 years ago|reply
You can check this [1] service that I prepared for myself then made it publicly available. For now it’s only sending popular stories as notification. Planning to add keyword feature.

[1] https://hnn.avci.me/

[+] tailspin2019|3 years ago|reply
Don’t have any suggestions but as an alternative to notifications, I wrote a script to check the HN API for keywords such as “outage” “downtime” “breached” and show the results on a TV screen in my office.

Has been quite useful for the ops side of what I work on!

[+] djbusby|3 years ago|reply
Cronjob to the Algolia Search API, send to your email.
[+] dinkledunk|3 years ago|reply
There's been several, but they always get abandoned after a year or two.
[+] shkaj|3 years ago|reply
Annoying how it doesn't show the text or anything for dead items.

Is there any way to query this API as if showdead is switched on?

[+] avg_dev|3 years ago|reply
I used to query flagged comments from time to time using the API, just out of some morbid curiosity. It definitely used to work for that; I am not sure if flagged items are in the same class as dead ones, though, or if they have since deliberately eliminated this capability. I eventually found more interesting things to do :)
[+] fileeditview|3 years ago|reply
For a few years I am working on the side on a HN client. One thing that is really sad is that there is now way to handle authentication properly as a 3rd party. The user basically has to trust you with her/his password or you have to "steal" the auth token from a login.
[+] wslh|3 years ago|reply
Again, it would be also great if we have a user's personal API to get our private info either.
[+] teleclimber|3 years ago|reply
Agreed. An read only API for my upvoted stories and comments would be great so I can preserve this data and use it outside of HN.
[+] O__________O|3 years ago|reply
Also be nice if per private user behavior, that a user was able to authorize API access to it without risking account lose.
[+] kogir|3 years ago|reply
It always amuses me when the API link in the footer floats up as a submission every few years.
[+] krapp|3 years ago|reply
It's almost as if a color scheme of grey on grey makes features hard to notice.