library(dplyr)
library(tidyr)
library(jsonlite)
library(XML)
library(RCurl)
times_url <-"https://api.nytimes.com/svc/topstories/v2/world.json"
df.times_url<-fromJSON(getForm(times_url, .params = c("api-key" ="3590677d16aa428aaf413d36dc0c1213")))
class(df.times_url)
## [1] "list"
df.times<-as.data.frame(df.times_url$results)
class(df.times)
## [1] "data.frame"
names(df.times)
## [1] "section" "subsection" "title"
## [4] "abstract" "url" "byline"
## [7] "item_type" "updated_date" "created_date"
## [10] "published_date" "material_type_facet" "kicker"
## [13] "des_facet" "org_facet" "per_facet"
## [16] "geo_facet" "multimedia" "short_url"
t(head(subset(df.times, select = c(title,byline,abstract,url))))
## 1
## title "Jair Bolsonaro, Far-Right Populist, Elected President of Brazil"
## byline "By ERNESTO LONDOÑO and SHASTA DARLINGTON"
## abstract "After choosing leftist presidents in four successive elections, Brazilians opted for a radical new course for Latin America’s largest nation."
## url "https://www.nytimes.com/2018/10/28/world/americas/jair-bolsonaro-brazil-election.html"
## 2
## title "Sri Lanka’s Political Crisis Turns Deadly"
## byline "By DHARISHA BASTIANS and JEFFREY GETTLEMAN"
## abstract "The bodyguard of a former cabinet minister was accused of firing on a crowd on Sunday, killing one person and seriously wounding two others."
## url "https://www.nytimes.com/2018/10/28/world/asia/sri-lanka-political-crisis.html"
## 3
## title "As Rich Nations Close the Door on Refugees, Uganda Welcomes Them"
## byline "By JOSEPH GOLDSTEIN"
## abstract "In Uganda, refugees are given land, the right to work, and freedom to move around. And far from prompting a backlash, Ugandans remain welcoming of refugees."
## url "https://www.nytimes.com/2018/10/28/world/africa/uganda-refugees.html"
## 4
## title "Brazil’s Polarizing New President, Jair Bolsonaro, in His Own Words"
## byline "By MARIANA SIMÕES"
## abstract "Brazil's new leader has made countless divisive statements about torture, democracy, women, gay people and others during his rise to power. We look at some of them."
## url "https://www.nytimes.com/2018/10/28/world/americas/brazil-president-jair-bolsonaro-quotes.html"
## 5
## title "They Escaped China’s Crackdown, but Now Wait in Limbo"
## byline "By CHRISTINA ANDERSON and CHRIS BUCKLEY"
## abstract "An ethnic Uighur Muslim family’s struggle to stay in Sweden illustrates the risks for a people whose plight, until recently, had received little attention."
## url "https://www.nytimes.com/2018/10/27/world/asia/china-uighurs-sweden-asylum.html"
## 6
## title "‘They Don’t Have Money’: Greece’s Prostitutes Hit Hard by Financial Crisis"
## byline "By ILIANA MAGRA"
## abstract "An industry that has seen most everything is suffering under rock-bottom prices after a decade-long crisis left no profession unscathed, degrading the lives of Greek citizens."
## url "https://www.nytimes.com/2018/10/27/world/europe/prostitutes-greece-crisis.html"