D607 Wk09 HW - Web APIs

Kyle Gilde

April 1, 2017

The Task

The New York Times web site provides a rich set of APIs, as described here: http://developer.nytimes.com/docs

You’ll need to start by signing up for an API key.

Your task is to choose one of the New York Times APIs, construct an interface in R to read in the JSON data, and transform it to an R dataframe.

Load Packages

## prettydoc  jsonlite     knitr 
##      TRUE      TRUE      TRUE

API Call

The top 20 most viewed articles in the last 30 days

base_uri <- "https://api.nytimes.com/svc/mostpopular/v2/"
popularity_metric <- "mostviewed/"
section <- "all-sections/"
time_period <- "30.json"
api_key <- "?api-key=016f630b0da546b796d27ee0f9bc3255"

url <- paste0(base_uri, popularity_metric, section, time_period, api_key)
my_results <- fromJSON(url)

my_df <- data.frame(my_results$results)

kable(my_df[, c(4:9, 13)], caption = "Here are the results.")
Here are the results.
section byline type title abstract published_date views
Opinion By MAUREEN DOWD Article Donald, This I Will Tell You Dear President Trump: Are we going to lose so much, we’ll get tired of losing? 2017-03-25 1
U.S. By MITCH SMITH Article New Ferguson Video Adds Wrinkle to Michael Brown Case A documentary says security footage suggests that the young man may not have been stealing from a Ferguson, Mo., convenience store before he was shot by the police. 2017-03-11 2
U.S. By ROBERT PEAR, THOMAS KAPLAN and MAGGIE HABERMAN Article In Major Defeat for Trump, Push to Repeal Health Law Fails House Republican leaders withdrew legislation to repeal the Affordable Care Act from the House floor before it could be defeated, a loss for President Trump. 2017-03-24 3
Opinion By NICHOLAS KRISTOF Article And Jesus Said Unto Paul of Ryan … A parable considers the Republican “health care” plan. 2017-03-16 4
Style By AMY KROUSE ROSENTHAL Article You May Want to Marry My Husband After learning she doesn’t have long to live, a woman composes a dating profile for the man she will leave behind. 2017-03-03 5
U.S. By MAGGIE HABERMAN and CHARLIE SAVAGE Article U.S. Attorney Preet Bharara Says He Was Fired After Refusing to Quit The Manhattan federal prosecutor was among 46 United States attorneys who had been ordered to submit their resignations. 2017-03-11 6
U.S. By DANIEL VICTOR Article Lack of Oxford Comma Could Cost Maine Company Millions in Overtime Dispute An appeals court ruling on Monday was a victory for truck drivers and punctuation pedants. 2017-03-16 7
World By KATRIN BENNHOLD and STEPHEN CASTLE Article Deadly Attack Near U.K. Parliament; Car Plows Victims on Westminster Bridge Prime Minister Theresa May, who was hastily evacuated from Parliament, called the assault a “sick and depraved terrorist attack.” 2017-03-22 8
U.S. By CHARLIE SAVAGE and MAGGIE HABERMAN Article Trump Abruptly Orders 46 Obama-Era Prosecutors to Resign The president told the holdover United States attorneys to tender their resignations immediately, including — surprisingly — Preet Bharara, the United States attorney in Manhattan. 2017-03-10 9
U.S. By LIAM STACK Article Donald Trump Jr. Criticizes London Mayor After Deadly Attack Mr. Trump, the son of the president, referenced on Twitter an out-of-context quote by London’s mayor, Sadiq Khan, from September. 2017-03-22 10
U.S. By LIAM STACK Article After Barring Girls for Leggings, United Airlines Defends Decision Passengers were turned away by a gate agent at Denver International Airport on Sunday morning for their attire, setting off a social media tempest. 2017-03-26 11
World By THE NEW YORK TIMES Article London Terrorist Attack: What We Know and Don’t Know Khalid Masood, 52, has been identified as the man who carried out an assault outside Britain’s Parliament that left three victims dead and about 40 others injured. 2017-03-22 12
U.S. By MATTHEW ROSENBERG, MAGGIE HABERMAN and ADAM GOLDMAN Article 2 White House Officials Helped Give Nunes Intelligence Reports The revelation fueled criticism that Representative Devin Nunes has been too eager to do the White House’s bidding, not run an independent investigation 2017-03-30 13
Opinion By CHARLES M. BLOW Article A Ticket to Hell As he’s done all his life, Donald Trump sold those around him a bill of goods. 2017-03-09 14
U.S. By PETER BAKER and JESSE DRUCKER Article Trump Wrote Off $100 Million in Losses in 2005, Leaked Forms Show The MSNBC host Rachel Maddow disclosed information from President Trump’s 2005 tax return on Tuesday night. 2017-03-14 15
U.S. By GLENN THRUSH and MAGGIE HABERMAN Article Trump Becomes Ensnared in Fiery G.O.P. Civil War The health bill’s defeat leaves the president facing a wrenching choice: ceding power to his party’s anti-establishment wing, or seeking other pathways to successful governing. 2017-03-25 16
World By CHRISTINE HAUSER and DANIEL VICTOR Article When the Kids Crash Your BBC Interview Two children interrupted a political-science professor live on the air while he was trying to explain the South Korea impeachment scandal. 2017-03-10 17
World By PETER BAKER and STEVEN ERLANGER Article Trump Offers No Apology for Claim on British Spying British officials were livid after the White House aired an unverified claim that Britain’s spy agency had monitored Mr. Trump during last year’s campaign at the behest of President Barack Obama. 2017-03-17 18
U.S. By ERIC LICHTBLAU and WILLIAM K. RASHBAUM Article White House Addresses Trump’s Unorthodox Call to Preet Bharara Despite being asked repeatedly on Saturday about the nature of the call, the White House was silent until Sunday, when it said the president was trying to extend his good wishes to Mr. Bharara. 2017-03-12 19
Well By GRETCHEN REYNOLDS Article The Best Exercise for Aging Muscles Certain kinds of exercise may mitigate the effects of aging at the cellular level. 2017-03-23 20