Access to breaking news headlines and articles from over 30,000 news sources and blogs through the newsAPI API.
The package newsAPI is an API wrapper/R client for accessing https://newsapi.org.
Go to newsapi.org and register to get an API KEY. Save the key as an environment variable.
This package gives access to breaking news headlines, and articles from over 30,000 news sources and blogs.
Each of these functions are detailed in this course and some examples are provided.
This method allows you to search for news sources by language. For example, to find all english language news sources, use the following code:
Once you have identified news source names (IDs) pas them to the get_articles() function. The following code, for example, retrive all articles from the search above.
# invoke library
library(newsAPI)
# get all english language news sources (made available by newsapi.org)
src <- get_sources(language = "en")
# preview data
print(src, width = 500)
## apply get_articles function to each news source
df <- lapply(src$id, get_articles)
## collapse into single data frame
df <- do.call("rbind", df)
## preview data
print(df, width = 500)
Command | Detail |
---|---|
get_sources() | Search for news source names (IDs) |
get_articles() | Get data by news source names (IDs) |
This tutorial uses the newsAPI package documentation
For attribution, please cite this work as
Warin (2020, March 30). Thierry Warin, PhD: [API] newsAPI. Retrieved from https://warin.ca/posts/api-newsAPI/
BibTeX citation
@misc{warin2020[api], author = {Warin, Thierry}, title = {Thierry Warin, PhD: [API] newsAPI}, url = {https://warin.ca/posts/api-newsAPI/}, year = {2020} }