## my obscured key NEWSAPI_KEY <- "4345e85e8ae1427480xxxxxxxxxxxxxx" ## save to .Renviron file cat( paste0("NEWSAPI_KEY=", NEWSAPI_KEY), append = TRUE, fill = TRUE, file = file.path("~", ".Renviron") )
## install script if (!"devtools" %in% installed.packages()) { install.packages("devtools") } devtools::install_github("mkearney/newsAPI") ## load package library(newsAPI)
## get all english language news sources (made available by newsapi.org) src <- get_sources(language = "en") ## preview data print(src, width = 500)
get_articles
function## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.