1
試圖將數據從NewsRiver API拉入R.特別想將提供的json轉換爲數據幀以供進一步分析。我也想能夠輸入我自己的搜索詞和我想從變量中搜索的域。如何將來自News River API的數據拉入R
試圖將數據從NewsRiver API拉入R.特別想將提供的json轉換爲數據幀以供進一步分析。我也想能夠輸入我自己的搜索詞和我想從變量中搜索的域。如何將來自News River API的數據拉入R
library(httr)
library(jsonlite)
set_config(config(ssl_verifypeer = 0L))
search_1 <- "Amazon"
search_2 <- "World Domination"
website <- "bloomberg.com"
url <- sprintf('https://api.newsriver.io/v2/search?query=text%%3A%s%%20OR%%20text%%3A%s%%20OR%%20website.domainName%%3A%s%%20OR%%20language%%3AEN&sortBy=_score&sortOrder=DESC&limit=100', search_1, search_2, website)
api_key <- "mykey"
news <- GET(url, add_headers(Authorization = paste(api_key, sep = "")))
news_txt <- content(news, as = "text")
news_china_df <- fromJSON(news_txt)