2

我正在尝试使用R中的httr包访问 RapidAPI,如下所示:

library(httr)
url <- "https://extract-news.p.rapidapi.com/v0/article"
queryString <- list(url = "https://www.theverge.com/2020/4/17/21224728/bill-gates-coronavirus-lies-5g-covid-19")
response <- VERB("GET", url, addheaders(x_rapidapi_key ="my-api-key", x_rapidapi_host = "extract-news.p.rapidapi.com"), query = queryString, contenttype("application/octet-stream"))
content(response, "text")

我也尝试访问其他 API。但是,我不断收到此错误消息:

Status: 401 

你能帮我解决这个问题吗?提前非常感谢!

4

1 回答 1

0

尝试使用content_type()andadd_headers而不是contenttypeandaddheaders告诉服务器您正在发送什么样的数据。在此处阅读有关 VERB 方法的更多信息。

library(httr)

url <- "https://extract-news.p.rapidapi.com/v0/article"

queryString <- list(url = "https://www.theverge.com/2020/4/17/21224728/bill-gates-coronavirus-lies-5g-covid-19")

response <- VERB("GET", url, add_headers(x_rapidapi-host = 'extract-news.p.rapidapi.com', x_rapidapi-key = '*************************', '), query = queryString, content_type("application/octet-stream"))

content(response, "text")
于 2021-09-01T09:53:42.843 回答