The New York Times web site provides a rich set of APIs, as described here: https://developer.nytimes.com/apis 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 into an R DataFrame.
library(httr)
library(jsonlite)
From the given website, I chose the “Most Popular API”, and the sub-category was most viewed articles. With registration of API, the API-Key is provided as ‘ARQt7sTVh2X4fGZidt7OKIMst3UMVzwM’. Finally, I was able to get the json format data set. below url is the website of the data.
url<-'https://api.nytimes.com/svc/mostpopular/v2/viewed/1.json?api-key=ARQt7sTVh2X4fGZidt7OKIMst3UMVzwM'
get_url <- GET(url, accept_json())
data <- content(get_url, as="text")
data <- fromJSON(data)
popular <- as.data.frame(data)
head(popular)
## status copyright
## 1 OK Copyright (c) 2021 The New York Times Company. All Rights Reserved.
## 2 OK Copyright (c) 2021 The New York Times Company. All Rights Reserved.
## 3 OK Copyright (c) 2021 The New York Times Company. All Rights Reserved.
## 4 OK Copyright (c) 2021 The New York Times Company. All Rights Reserved.
## 5 OK Copyright (c) 2021 The New York Times Company. All Rights Reserved.
## 6 OK Copyright (c) 2021 The New York Times Company. All Rights Reserved.
## num_results results.uri
## 1 20 nyt://article/2d7a5168-11c2-5168-aea3-96ac42a2717e
## 2 20 nyt://article/f018d7fe-518a-562b-ade0-7e5f1f247d6d
## 3 20 nyt://article/4fdc5597-54ae-5b6a-bf11-4ab43c2be091
## 4 20 nyt://article/8a1be547-da1c-5d96-92dd-050d8a511570
## 5 20 nyt://article/558d0e2e-538e-50b1-a6ad-21ea4b0d058b
## 6 20 nyt://article/5ffc8f14-3804-5dd6-8381-17163dd00c7c
## results.url
## 1 https://www.nytimes.com/2021/10/21/us/alec-baldwin-shooting-rust-movie.html
## 2 https://www.nytimes.com/2021/10/23/us/alec-baldwin-rust-shooting.html
## 3 https://www.nytimes.com/2021/10/23/sports/basketball/vanessa-bryant-helicopter-crash-lawsuit.html
## 4 https://www.nytimes.com/2021/10/22/realestate/buy-nothing-facebook-group.html
## 5 https://www.nytimes.com/2021/10/22/style/amanda-knox-ten-years-later.html
## 6 https://www.nytimes.com/article/alec-baldwin-shooting-investigation.html
## results.id results.asset_id results.source results.published_date
## 1 1e+14 1e+14 New York Times 2021-10-21
## 2 1e+14 1e+14 New York Times 2021-10-23
## 3 1e+14 1e+14 New York Times 2021-10-23
## 4 1e+14 1e+14 New York Times 2021-10-22
## 5 1e+14 1e+14 New York Times 2021-10-22
## 6 1e+14 1e+14 New York Times 2021-10-23
## results.updated results.section results.subsection results.nytdsection
## 1 2021-10-23 19:08:48 U.S. u.s.
## 2 2021-10-24 12:31:50 U.S. u.s.
## 3 2021-10-24 12:29:34 Sports N.B.A. sports
## 4 2021-10-22 14:16:44 Real Estate real estate
## 5 2021-10-23 12:36:15 Style style
## 6 2021-10-24 11:53:55 Movies movies
## results.adx_keywords
## 1 Movies;Deaths (Fatalities);Firearms;Baldwin, Alec;Hutchins, Halyna (1979-2021);Souza, Joel (1973- );Santa Fe (NM);New Mexico
## 2 Firearms;Workplace Hazards and Violations;Movies;Accidents and Safety;Deaths (Fatalities);Baldwin, Alec;Hutchins, Halyna (1979-2021);Santa Fe (NM)
## 3 Suits and Litigation (Civil);Helicopters;Aviation Accidents, Safety and Disasters;Deaths (Fatalities);Bryant, Gianna (2006-20);Bryant, Kobe;Bryant, Vanessa (1982- );Villanueva, Alex (1963- );Los Angeles County Sheriff's Department;Mamba Sports Academy;Los Angeles County (Calif)
## 4 Social Media;Sustainable Living;Facebook Inc;Buy Nothing Project
## 5 Content Type: Personal Profile;False Arrests, Convictions and Imprisonments;Murders, Attempted Murders and Homicides;Knox, Amanda;Kercher, Meredith;Italy;Perugia (Italy);Seattle (Wash)
## 6 Baldwin, Alec;Souza, Joel (1973- );Hutchins, Halyna (1979-2021);Santa Fe (NM)
## results.column results.byline
## 1 NA By Simon Romero, Julia Jacobs and Glenn Thrush
## 2 NA By Simon Romero and Julia Jacobs
## 3 NA By Jonathan Abrams and Kevin Draper
## 4 NA By Ronda Kaysen
## 5 NA By Jessica Bennett
## 6 NA By Maggie Astor, Glenn Thrush, Simon Romero and Julia Jacobs
## results.type
## 1 Article
## 2 Article
## 3 Article
## 4 Article
## 5 Article
## 6 Article
## results.title
## 1 Alec Baldwin Was Told Gun in Fatal Shooting on Set Was Safe, Officials Say
## 2 Alec Baldwin Film Set Had Previous Accidental Gun Discharges, Crew Members Say
## 3 Vanessa Bryant, in Deposition, Describes Learning of Deaths of Kobe and Gianna
## 4 Inside the World of Buy Nothing, Where Dryer Lint Is a Hot Commodity
## 5 Amanda Knox Was Exonerated. That Doesn’t Mean She’s Free.
## 6 What We Know About the Fatal Shooting on Alec Baldwin’s New Mexico Movie Set
## results.abstract
## 1 The actor was told a gun being used as a prop was safe before he fired it on the set of “Rust,” killing the film’s cinematographer and wounding its director, law enforcement officials said.
## 2 They expressed concerns over gun mishaps and working conditions just days before the shooting that killed the cinematographer Halyna Hutchins.
## 3 Bryant was being questioned by a lawyer defending Los Angeles County in her lawsuit about the sharing of photos of human remains from the helicopter crash that killed nine people.
## 4 From medical supplies to half-eaten birthday cakes, Buy Nothing is fostering a quirky sense of community that is mostly fun and occasionally irritating.
## 5 Ten years after being cleared of a heinous crime, she is still trying to tell her story on her own terms.
## 6 The authorities are investigating the death of the cinematographer Halyna Hutchins on the set of “Rust” in Santa Fe County. Here’s what we know.
## results.des_facet
## 1 Movies, Deaths (Fatalities), Firearms
## 2 Firearms, Workplace Hazards and Violations, Movies, Accidents and Safety, Deaths (Fatalities)
## 3 Suits and Litigation (Civil), Helicopters, Aviation Accidents, Safety and Disasters, Deaths (Fatalities)
## 4 Social Media, Sustainable Living
## 5 Content Type: Personal Profile, False Arrests, Convictions and Imprisonments, Murders, Attempted Murders and Homicides
## 6
## results.org_facet
## 1
## 2
## 3 Los Angeles County Sheriff's Department, Mamba Sports Academy
## 4 Facebook Inc, Buy Nothing Project
## 5
## 6
## results.per_facet
## 1 Baldwin, Alec, Hutchins, Halyna (1979-2021), Souza, Joel (1973- )
## 2 Baldwin, Alec, Hutchins, Halyna (1979-2021)
## 3 Bryant, Gianna (2006-20), Bryant, Kobe, Bryant, Vanessa (1982- ), Villanueva, Alex (1963- )
## 4
## 5 Knox, Amanda, Kercher, Meredith
## 6 Baldwin, Alec, Souza, Joel (1973- ), Hutchins, Halyna (1979-2021)
## results.geo_facet
## 1 Santa Fe (NM), New Mexico
## 2 Santa Fe (NM)
## 3 Los Angeles County (Calif)
## 4
## 5 Italy, Perugia (Italy), Seattle (Wash)
## 6 Santa Fe (NM)
## results.media
## 1 image, photo, Alec Baldwin in the parking lot outside the sheriff’s office in Santa Fe, N.M., after he was questioned about the shooting on the set of the film “Rust” on Thursday., Jim Weber/Santa Fe New Mexican, via Associated Press, 1, https://static01.nyt.com/images/2021/10/22/us/22baldwin-briefing-hp-promo1/22xp-newmexico2-thumbStandard.jpg, https://static01.nyt.com/images/2021/10/22/us/22baldwin-briefing-hp-promo1/22baldwin-briefing-hp-promo1-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2021/10/22/us/22baldwin-briefing-hp-promo1/22baldwin-briefing-hp-promo1-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 2 image, photo, A bouquet hangs outside the Bonanza Creek Film Ranch, where Alec Baldwin fatally shot the cinematographer Halyna Hutchins and wounded a director when he discharged a prop gun., Andres Leighton/Associated Press, 1, https://static01.nyt.com/images/2021/10/23/multimedia/23baldwin-shooting-03/23baldwin-shooting-03-thumbStandard.jpg, https://static01.nyt.com/images/2021/10/23/multimedia/23baldwin-shooting-03/merlin_196722828_73af05ea-20aa-4406-b98d-c739cf0ff91c-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2021/10/23/multimedia/23baldwin-shooting-03/merlin_196722828_73af05ea-20aa-4406-b98d-c739cf0ff91c-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 3 image, photo, Vanessa Bryant, the widow of the Los Angeles Lakers superstar Kobe Bryant, said in a deposition that it took hours for her to learn officially that Kobe and their daughter Gianna had been killed in a helicopter crash., Maddie Meyer/Getty Images, 1, https://static01.nyt.com/images/2021/10/23/sports/23nba-vanessa-bryant-1/23nba-vanessa-bryant-1-thumbStandard.jpg, https://static01.nyt.com/images/2021/10/23/sports/23nba-vanessa-bryant-1/merlin_187816056_ad7a12a0-a18c-4c25-9993-843820d09714-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2021/10/23/sports/23nba-vanessa-bryant-1/merlin_187816056_ad7a12a0-a18c-4c25-9993-843820d09714-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 4 image, photo, , Trisha Krauss, 1, https://static01.nyt.com/images/2021/10/24/realestate/22Rightathome-illo/22Rightathome-thumbStandard.jpg, https://static01.nyt.com/images/2021/10/24/realestate/22Rightathome-illo/22Rightathome-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2021/10/24/realestate/22Rightathome-illo/22Rightathome-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 5 image, photo, “Your world is so limited when you’re a cardboard cutout,” said Ms. Knox, 34, with her daughter, Eureka., Ricardo Nagaoka for The New York Times, 1, https://static01.nyt.com/images/2021/10/24/fashion/23KNOX1/23KNOX1-thumbStandard.jpg, https://static01.nyt.com/images/2021/10/24/fashion/23KNOX1/23KNOX1-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2021/10/24/fashion/23KNOX1/23KNOX1-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 6 image, photo, A distraught Alec Baldwin in the parking lot outside the Santa Fe County Sheriff’s Office on Thursday after answering questions about the shooting., Jim Weber/Santa Fe New Mexican, via Associated Press, 1, https://static01.nyt.com/images/2021/10/23/insider/23baldwin-A1/baldwin-road1-thumbStandard.jpg, https://static01.nyt.com/images/2021/10/23/insider/23baldwin-A1/baldwin-road1-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2021/10/23/insider/23baldwin-A1/baldwin-road1-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## results.eta_id
## 1 0
## 2 0
## 3 0
## 4 0
## 5 0
## 6 0
The popular data has 20 observations and 25 variables. There is something new in this popular data that I have never seen before. under the results.media each variable has 10 sub-variables. I need to find out what is this really meaning.