2

I am trying to access a RapidAPI with the httr package in R as follows:

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")

I tried accessing other APIs too. However, I keep getting this error message:

Status: 401 

Could you please help me solve this issue? Thanks a lot in advance!

seb-29
  • 51
  • 2
  • There is probably and issue with your api key. It's probably expired or something else. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 – dcruvolo May 20 '21 at 16:41
  • Thanks @dcruvolo! I checked, but could not detect any issue with my api key. Any other idea what the issue might be? – seb-29 May 21 '21 at 13:39

1 Answers1

0

Try using content_type() and add_headers instead of contenttype and addheaders to tell the server what sort of data you are sending. Read more about the VERB method here.

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")
Pratham
  • 497
  • 3
  • 7
  • Hi, I am having the same issue on `R` that returns 401 message. The code you posted is not working, is there any way to tackle this issue?? Many thanks! – Duck Sep 25 '21 at 16:42