How do I continuously get the newest articles?
Use the stream of new articles endpoint, minuteStreamArticles (in the documentation: "Get stream of new articles"). It returns articles that match your query and were added since your last call:
- Call it as often as you need (every minute, every 10 minutes, every hour). It can return articles added in up to the last 4 hours (240 minutes), and at most 2,000 articles per call (no paging), so poll often enough not to exceed that.
- Pass the cursor from the previous response: set
recentActivityArticlesNewsUpdatesAfterUri(and the Blog / Pr variants for those data types) to the value ofnewestUrifrom the previous response, e.g."newestUri": { "news": "7546857244" }. Then no article is returned twice. Don't userecentActivityArticlesUpdatesAfterMinsAgotogether with this approach. - Article URIs are not strictly increasing - articles take different times to get through our processing - so an article with a URI lower than your cursor is expected and is not a duplicate.
- Cost: based on the number of returned articles (1 token per 100 articles). A call that returns nothing still uses tokens.
- The stream doesn't accept topic pages or the full advanced query language; use the filters described for the endpoint in the documentation.
Python examples: FeedOfNewArticlesExamples.py (for events: FeedOfNewEventsExamples.py).
If you filter the stream for articles that belong to an event, keep in mind that events are computed with a delay after the articles are added. Poll less frequently, or continue from the URI of the newest article that already has an event.