Assignment 9

Daniel DeBonis

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.

Certian packages are necessary in dealing with the JSON format of the API connection.

library(jsonlite)
library(httr)
library(httr2)

I selected the Top Stories API. I decided to search for the top stories that are considered World News.

worldraw <- GET("https://api.nytimes.com/svc/topstories/v2/world.json?api-key=V3mpHG49JtsZy4eL53sGtlphnbDHZab3")
worldtext <- content(worldraw, as = 'text') 
## No encoding supplied: defaulting to UTF-8.
worldjson <- fromJSON(worldtext)
worlddf <- worldjson$results
head(worlddf)
##   section subsection
## 1   world       asia
## 2   world     europe
## 3   world       asia
## 4   world middleeast
## 5   world     europe
## 6   world       asia
##                                                                     title
## 1  Myanmar Earthquake Toll Surpasses 1,600 Dead Amid Search for Survivors
## 2                                The Secret History of the War in Ukraine
## 3               Earthquake Damages Myanmar’s Religious and Heritage Sites
## 4          Syria’s Leader Announces New Government After Ousting Dictator
## 5 ‘A Great Emboldening’: Trump Inspires Wannabe Authoritarians Everywhere
## 6          Taliban Appears to Free American Woman Detained in Afghanistan
##                                                                                                                                                                                      abstract
## 1          Aid workers delivered the first shipments of help to Myanmar, but will have to cross a country buckled by the disaster and divided by civil war, arms dealers and drug syndicates.
## 2                                                                        This is the untold story of America’s hidden role in Ukrainian military operations against Russia’s invading armies.
## 3                                    The deadly quake in Myanmar damaged over 3,000 buildings, including about 150 mosques and pagodas, in the government’s latest count on Saturday morning.
## 4 The choice of cabinet officials was seen as a litmus test for whether the rebels who ousted Bashar al-Assad would deliver on a pledge to create a government representative of all Syrians.
## 5                                                 President Trump has turned a central precept of American diplomacy on its head, embracing fellow leaders who abandon democratic principles.
## 6                      President Trump and a former U.S. ambassador to Afghanistan shared a video of a woman identified as Faye Hall thanking the president for her release from Afghanistan.
##                                                                                                                 url
## 1                                             https://www.nytimes.com/2025/03/29/world/asia/myanmar-earthquake.html
## 2                https://www.nytimes.com/interactive/2025/03/29/world/europe/us-ukraine-military-war-wiesbaden.html
## 3            https://www.nytimes.com/video/world/asia/100000010080759/myanmar-heritage-sites-damage-earthquake.html
## 4                                https://www.nytimes.com/2025/03/29/world/middleeast/syria-government-al-shara.html
## 5                             https://www.nytimes.com/2025/03/29/world/europe/trump-authoritarians-inspiration.html
## 6 https://www.nytimes.com/2025/03/29/world/asia/taliban-appears-to-free-american-woman-detained-in-afghanistan.html
##                                                      uri
## 1     nyt://article/9ac862af-ced7-510b-8cb5-8eac092c85cf
## 2 nyt://interactive/9ac356be-575d-54ad-a5db-c63e066477b4
## 3       nyt://video/dc56b39c-8cb5-5239-920a-bdc9b2bb19c6
## 4     nyt://article/30fccc7d-68ea-5984-a896-cd23c11ad387
## 5     nyt://article/7e5b3ca8-b225-5804-ab38-9b585195dec1
## 6     nyt://article/b203e080-2381-55c4-b8c4-e13ad368926b
##                                    byline   item_type              updated_date
## 1           By Sui-Lee Wee and Alan Yuhas     Article 2025-03-30T01:05:22-04:00
## 2                          By Adam Entous Interactive 2025-03-30T00:00:16-04:00
## 3                   By McKinnon de Kuyper       Video 2025-03-29T12:27:55-04:00
## 4 By Carlotta Gall and Christina Goldbaum     Article 2025-03-29T21:00:57-04:00
## 5                     By Michael D. Shear     Article 2025-03-29T21:13:07-04:00
## 6                          By Eve Sampson     Article 2025-03-29T19:53:26-04:00
##                created_date            published_date material_type_facet
## 1 2025-03-29T14:21:38-04:00 2025-03-29T14:21:38-04:00                    
## 2 2025-03-29T19:09:17-04:00 2025-03-29T19:09:17-04:00                    
## 3 2025-03-29T12:27:55-04:00 2025-03-29T12:27:55-04:00                    
## 4 2025-03-29T18:59:30-04:00 2025-03-29T18:59:30-04:00                    
## 5 2025-03-29T00:01:08-04:00 2025-03-29T00:01:08-04:00                    
## 6 2025-03-29T18:20:47-04:00 2025-03-29T18:20:47-04:00                    
##          kicker
## 1              
## 2              
## 3              
## 4              
## 5 news analysis
## 6              
##                                                                                                                                                                                                                                                                                                des_facet
## 1                                                                                                                                                                            Myanmar Earthquake (March 28, 2025), Earthquakes, Deaths (Fatalities), War and Armed Conflicts, Defense and Military Forces
## 2 vis-design, Russian Invasion of Ukraine (2022), United States International Relations, United States Politics and Government, Drones (Pilotless Planes), United States Defense and Military Forces, Missiles and Missile Defense Systems, War and Armed Conflicts, Espionage and Intelligence Services
## 3                                                                                                                                                                                                                                         Earthquakes, Historic Buildings and Sites, Religion and Belief
## 4                                                                                                                                                                                                                                                       Politics and Government, War and Armed Conflicts
## 5                                                                              United States Politics and Government, United States International Relations, Authoritarianism (Theory and Philosophy), Foreign Aid, Courts and the Judiciary, Democracy (Theory and Philosophy), International Relations
## 6                                                                                                                                               United States Politics and Government, United States International Relations, International Relations, Afghanistan War (2001- ), Kidnapping and Hostages
##                                                                                                                                                                                                                                                                          org_facet
## 1                                                                                                                                                                                                                                                                                 
## 2 Central Intelligence Agency, Defense Department, Defense Intelligence Agency, Joint Chiefs of Staff, Main Directorate of Intelligence (HUR) (Ukraine), National Geospatial-Intelligence Agency, National Security Agency, North Atlantic Treaty Organization, United States Navy
## 3                                                                                                                                                                                                                                                                                 
## 4                                                                                                                                                                                                                                                                                 
## 5                                                                                                                                                                                                                               United States Agency for International Development
## 6                                                                                                                                                                                                                                                                          Taliban
##                                                                                                                                                                                                                                                                                                                           per_facet
## 1                                                                                                                                                                                                                                                                                                                   Min Aung Hlaing
## 2 Biden, Joseph R Jr, Blinken, Antony J, Budanov, Kyrylo, Cavoli, Christopher G, Kondratiuk, Valeriy, Milley, Mark A, Prigozhin, Yevgeny V, Putin, Vladimir V, Reznikov, Oleksii, Sodol, Yurii, Surovikin, Sergei, Syrsky, Oleksandr, Trump, Donald J, Wallace, Ben (1970- ), Yermak, Andriy, Zaluzhny, Valery, Zelensky, Volodymyr
## 3                                                                                                                                                                                                                                                                                                                                  
## 4                                                                                                                                                                                                                                                              al-Shara, Ahmed (Abu Mohammad al-Jolani) (1982- ), Assad, Bashar al-
## 5                                                                                                                                                                                                                  Ben-Ghiat, Ruth, Biden, Joseph R Jr, Netanyahu, Benjamin, Vucic, Aleksandar, Witkoff, Steven, Trump, Donald J Jr
## 6                                                                                                                                                                                                                                                                                                Trump, Donald J, Khalilzad, Zalmay
##                                                                             geo_facet
## 1                                           Mandalay (Myanmar), Myanmar, India, China
## 2                                                      Ukraine, Russia, United States
## 3                                                                             Myanmar
## 4                                                 Idlib (Syria), Syria, United States
## 5 Belgrade (Serbia), Europe, Israel, Istanbul (Turkey), Turkey, Serbia, United States
## 6                                                                         Afghanistan
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             multimedia
## 1                                                       https://static01.nyt.com/images/2025/03/29/multimedia/29int-myanmar-quake-ledeall-01-cjvp/29int-myanmar-quake-ledeall-01-cjvp-superJumbo.jpg, https://static01.nyt.com/images/2025/03/29/multimedia/29int-myanmar-quake-ledeall-01-cjvp/29int-myanmar-quake-ledeall-01-cjvp-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2025/03/29/multimedia/29int-myanmar-quake-ledeall-01-cjvp/29int-myanmar-quake-ledeall-01-cjvp-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1365, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, Rescue teams working to free trapped residents at the destroyed Sky Villa Condominium in Mandalay, Myanmar, on Saturday, a day after the earthquake struck., Rescue teams working to free trapped residents at the destroyed Sky Villa Condominium in Mandalay, Myanmar, on Saturday, a day after the earthquake struck., Rescue teams working to free trapped residents at the destroyed Sky Villa Condominium in Mandalay, Myanmar, on Saturday, a day after the earthquake struck., Sai Aung Main/Agence France-Presse — Getty Images, Sai Aung Main/Agence France-Presse — Getty Images, Sai Aung Main/Agence France-Presse — Getty Images
## 2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      https://static01.nyt.com/images/2025/03/18/multimedia/00wiesbaden-intro-bakhmut-flcz-promo/00wiesbaden-intro-bakhmut-flcz-superJumbo.jpg, https://static01.nyt.com/images/2025/03/18/multimedia/00wiesbaden-intro-bakhmut-flcz-promo/00wiesbaden-intro-bakhmut-flcz-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2025/03/18/multimedia/00wiesbaden-intro-bakhmut-flcz-promo/00wiesbaden-intro-bakhmut-flcz-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1365, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, , , , Tyler Hicks, Tyler Hicks, Tyler Hicks
## 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  https://static01.nyt.com/images/2025/03/29/world/asia/Brick_Monastery_AFP/Brick_Monastery_AFP-superJumbo.png, https://static01.nyt.com/images/2025/03/29/world/asia/Brick_Monastery_AFP/Brick_Monastery_AFP-threeByTwoSmallAt2X.png, https://static01.nyt.com/images/2025/03/29/world/asia/Brick_Monastery_AFP/Brick_Monastery_AFP-thumbLarge.png, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1080, 400, 150, 1620, 600, 150, image, image, image, photo, photo, photo, , , , AFP, AFP, AFP
## 4                                                                                                                                                                                                                                                                         https://static01.nyt.com/images/2025/03/29/multimedia/29int-syria-government-HFO-tvhk/29int-syria-government-HFO-tvhk-superJumbo.jpg, https://static01.nyt.com/images/2025/03/29/multimedia/29int-syria-government-HFO-tvhk/29int-syria-government-HFO-tvhk-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2025/03/29/multimedia/29int-syria-government-HFO-tvhk/29int-syria-government-HFO-tvhk-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1408, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, Syria’s interim president, Ahmed al-Shara, announcing the formation of a new government, in Damascus, Syria, on Saturday., Syria’s interim president, Ahmed al-Shara, announcing the formation of a new government, in Damascus, Syria, on Saturday., Syria’s interim president, Ahmed al-Shara, announcing the formation of a new government, in Damascus, Syria, on Saturday., Khalil Ashawi/Reuters, Khalil Ashawi/Reuters, Khalil Ashawi/Reuters
## 5 https://static01.nyt.com/images/2025/03/27/multimedia/00int-emboldened-trump-01-tbhq/00int-emboldened-trump-01-tbhq-superJumbo.jpg, https://static01.nyt.com/images/2025/03/27/multimedia/00int-emboldened-trump-01-tbhq/00int-emboldened-trump-01-tbhq-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2025/03/27/multimedia/00int-emboldened-trump-01-tbhq/00int-emboldened-trump-01-tbhq-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 1365, 400, 150, 2048, 600, 150, image, image, image, photo, photo, photo, Riot police officers use pepper spray on a protester in Turkey, during demonstrations that erupted after the arrest of Istanbul’s Mayor Ekrem Imamoglu — the main political rival of Turkey’s president., Riot police officers use pepper spray on a protester in Turkey, during demonstrations that erupted after the arrest of Istanbul’s Mayor Ekrem Imamoglu — the main political rival of Turkey’s president., Riot police officers use pepper spray on a protester in Turkey, during demonstrations that erupted after the arrest of Istanbul’s Mayor Ekrem Imamoglu — the main political rival of Turkey’s president., Huseyin Aldemir/Associated Press, Huseyin Aldemir/Associated Press, Huseyin Aldemir/Associated Press
## 6                                                                                                                                                                                                                                https://static01.nyt.com/images/2025/03/29/multimedia/29trump-news-taliban-tgvc/29trump-news-taliban-tgvc-superJumbo.jpg, https://static01.nyt.com/images/2025/03/29/multimedia/29trump-news-taliban-tgvc/29trump-news-taliban-tgvc-threeByTwoSmallAt2X.jpg, https://static01.nyt.com/images/2025/03/29/multimedia/29trump-news-taliban-tgvc/29trump-news-taliban-tgvc-thumbLarge.jpg, Super Jumbo, threeByTwoSmallAt2X, Large Thumbnail, 974, 400, 150, 1461, 600, 150, image, image, image, photo, photo, photo, In this image the AFP obtained from a diplomatic source in Kabul, an American woman is shown, speaking on the phone after being released by the Taliban., In this image the AFP obtained from a diplomatic source in Kabul, an American woman is shown, speaking on the phone after being released by the Taliban., In this image the AFP obtained from a diplomatic source in Kabul, an American woman is shown, speaking on the phone after being released by the Taliban., via Getty Images, via Getty Images, via Getty Images
##   short_url
## 1          
## 2          
## 3          
## 4          
## 5          
## 6

The linked API had a lot of information on each article, such as the region of the world concerned, title, author(s), links, and many other variables of interest. If I wanted to do further analysis, an important step would be to specify only the relevant columns be included upon converting from JSON to a data frame in R.