We’ve signed up for an API key from developers.nytimes.com, and activated it for the “TimesWire” API: https://developer.nytimes.com/docs/timeswire-product/1/overview
Our API key is: kgDYfnqUUHLjwSkEA4gUUG8UQpBufNMs
We append this to the NYTimes URL to make our initial request.
Using “fromJSON” we can create a JSON object in R, which is easily coerced into a data frame.
Finally, we take a smaller subset of this data frame for a more presentable slice of the data.
nyt_api_url <- "https://api.nytimes.com/svc/news/v3/content/all/all.json?api-key=kgDYfnqUUHLjwSkEA4gUUG8UQpBufNMs"
json_object <- fromJSON(nyt_api_url)
nyt_df <- as.data.frame(json_object)
final_df <- subset(nyt_df, select = c(results.section:results.byline))
final_df
## results.section results.subsection
## 1 Sports
## 2 U.S. Politics
## 3 U.S. Politics
## 4 World Middle East
## 5 Business
## 6 U.S. Politics
## 7 Opinion
## 8 Opinion
## 9 U.S. Politics
## 10 Business Media
## 11 Opinion
## 12 Opinion Letters
## 13 Opinion
## 14 Opinion
## 15 Sports
## 16 World Middle East
## 17 Sports
## 18 U.S.
## 19 Crosswords & Games
## 20 U.S. Politics
## results.title
## 1 Miami Open: Simona Halep and Novak Djokovic Win Three-Setters
## 2 Trump Declares Victory, and a War on His Enemies
## 3 A Cloud Over Trumps Presidency Is Lifted
## 4 Iraq Ferry Accident Sets Off Political Upheaval in Mosul
## 5 At the 737 Max Factory, Pilots Simulate New Boeing Software
## 6 No Impeachment in View, but Democrats Push On With Investigations of Trump
## 7 Its Bigger Than Mueller and Trump
## 8 No Collusion, No Exoneration
## 9 Democratic Presidential Candidates Call for the Release of Muellers Full Report
## 10 Mueller Report News Interrupts Sunday Golf and Video Games
## 11 The Many Problems With the Barr Letter
## 12 What Mueller Found, and Didnt Find
## 13 China Performs Its Song and Dance
## 14 It Will Take More Than a $34,000 Drug to Stop Postpartum Depression
## 15 Rob Gronkowski Retires From N.F.L. With Instagram Post
## 16 Netanyahu Lands in U.S., but New Scandal Could Mar His Big Moment
## 17 Islanders Blank Coyotes and Keep Pace With the Capitals
## 18 Women Becoming Marines: I Will No Longer Be in Your Vocabulary
## 19 Old Records
## 20 Kirsten Gillibrand, Outside a Trump Hotel, Calls the President a Coward
## results.abstract
## 1 Halep will next face Venus Williams, who had an easier time in defeating Daria Kasatkina.
## 2 Like everyone else in the country, the president had been forced to wait while in Washington, the attorney general pored over the special counsels report and decided what to make public.
## 3 The end of the special counsels investigation without findings of collusion with Russia fortified the president for the battles to come, including his campaign for re-election.
## 4 After a ferry disaster that killed at least 97, Parliament fired the governor of Nineveh Province and replaced him with a crisis cell to improve government services and root out endemic corruption.
## 5 Pilots from five airlines gathered in Renton, Wash., on Saturday to review proposed changes to the software of the 737 Max, two of which have crashed.
## 6 Democrats vowed to gain access to the full special counsel report, and seized on statements that were less than definitive in the attorney generals summary of it.
## 7 Trumpism follows a historical pattern: Whenever black people make progress, white people respond forcefully.
## 8 A Trump-friendly attorney generals letter doesnt do justice to the special counsels investigation. Release his whole report.
## 9 The candidates said Attorney General William P. Barrs summary of the special counsels investigation was inadequate.
## 10 The news media began assessing its own coverage of the investigation hours before a breaking story punctuated a long period of speculative TV talk.
## 11 By unilaterally concluding that Mr. Trump did not obstruct justice, the attorney general has made it imperative that the public see the Mueller report.
## 12 Readers react to the attorney generals summary of the special counsels report.
## 13 A competition is being waged for loyalties in the South Pacific.
## 14 We need to pay more attention to the way our culture abuses and isolates new mothers.
## 15 The Patriots dominant tight end, known for his combination of size and speed, played a key part in Super Bowl LIII.
## 16 With the Israeli election weeks away, Netanyahus trip to Washington was supposed to show off his statesmanship. A scandal followed him here.
## 17 Robin Lehner stopped 31 shots for the Islanders, who moved ahead of the Penguins for second in the Metropolitan Division.
## 18 Women make up 8 percent of U.S. Marines. The military base at Parris Island, S.C., is where these women train.
## 19 Kevin Christian and Andrea Carla Michaels open our solving week.
## 20 Ms. Gillibrand, who has struggled for traction in the 2020 race, launched a frontal attack on Mr. Trump and called for the public release of the special counsels report.
## results.url
## 1 https://www.nytimes.com/2019/03/24/sports/miami-open-halep-djokovic.html
## 2 https://www.nytimes.com/2019/03/24/us/politics/trump-mueller-report.html
## 3 https://www.nytimes.com/2019/03/24/us/politics/trump-mueller-investigation.html
## 4 https://www.nytimes.com/2019/03/24/world/middleeast/iraq-mosul-corruption.html
## 5 https://www.nytimes.com/2019/03/24/business/boeing-737-pilots-simulators.html
## 6 https://www.nytimes.com/2019/03/24/us/politics/trump-impeachment-democrats.html
## 7 https://www.nytimes.com/2019/03/24/opinion/trump-mueller-white-supremacy.html
## 8 https://www.nytimes.com/2019/03/24/opinion/mueller-report-trump-investigation.html
## 9 https://www.nytimes.com/2019/03/24/us/politics/barr-letter-2020-democrats.html
## 10 https://www.nytimes.com/2019/03/24/business/media/mueller-report-news-media.html
## 11 https://www.nytimes.com/2019/03/24/opinion/barr-mueller-report.html
## 12 https://www.nytimes.com/2019/03/24/opinion/letters/trump-mueller-report.html
## 13 https://www.nytimes.com/2019/03/24/opinion/china-taiwan.html
## 14 https://www.nytimes.com/2019/03/24/opinion/postpartum-depression-zulresso.html
## 15 https://www.nytimes.com/2019/03/24/sports/rob-gronkowski-retires-patriots.html
## 16 https://www.nytimes.com/2019/03/24/world/middleeast/netanyahu-scandal-submarines-trump.html
## 17 https://www.nytimes.com/2019/03/24/sports/nhl-islanders-coyotes.html
## 18 https://www.nytimes.com/2019/03/24/us/female-marines-parris-island-crucible.html
## 19 https://www.nytimes.com/2019/03/24/crosswords/daily-puzzle-2019-03-25.html
## 20 https://www.nytimes.com/2019/03/24/us/politics/gillibrand-trump-2020.html
## results.byline
## 1 By AGENCE FRANCE-PRESSE
## 2 By MARK LANDLER and MAGGIE HABERMAN
## 3 By PETER BAKER
## 4 By ALISSA J. RUBIN and FALIH HASSAN
## 5 By DAVID GELLES
## 6 By NICHOLAS FANDOS
## 7 By CHARLES M. BLOW
## 8 By THE EDITORIAL BOARD
## 9 By SANDRA E. GARCIA
## 10 By JIM WINDOLF
## 11 By NEAL K. KATYAL
## 12 <NA>
## 13 By HENG
## 14 By ELISA ALBERT and JENNIFER BLOCK
## 15 By BENJAMIN HOFFMAN
## 16 By DAVID M. HALBFINGER
## 17 By THE ASSOCIATED PRESS
## 18 By LYNSEY ADDARIO
## 19 By DEB AMLEN
## 20 By SHANE GOLDMACHER