Error working with jsonlite R package - r

I want to read in data from an API to R using jsonlite, but gives me the error message shown below. Before some months, it was working fine. What could be the reason that it is not working now? I am trying to get data from the openFDA API:
library(jsonlite)
fda=fromJSON("https://api.fda.gov/drug/event.json?search=receivedate:[20040101+TO+20160101]&count=receivedate")
Error in open.connection(con, "rb") :
Peer certificate cannot be authenticated with given CA certificates

Related

Web Scraping with R: error related to reset of the connection with server

I have a problem with obtaining data from specific website - when trying to download raw website data with R 3.6.3 using following example code:
website_raw <- readLines("https://tge.pl/gaz-rdn?dateShow=09-02-2022")
The result I got is:
Error in file(con, "r") : cannot open the connection In addition: Warning message: In file(con, "r") : InternetOpenUrl failed: 'the connection with the server was reset'
readLines() method used to work fine on this website but from one week on it fails. I've tried also download.file() method: at the beginning the result was the same (error, connection reset) but after setting options(download.file.method = "libcurl"), website file starts to download but then it suddenly stops with information:
trying URL 'https://tge.pl/gaz-rdn?dateShow=09-02-2022'
Error in download.file("https://tge.pl/gaz-rdn?dateShow=09-02-2022", "test.html") :
cannot open URL 'https://tge.pl/gaz-rdn?dateShow=09-02-2022'
In addition: Warning message:
In download.file("https://tge.pl/gaz-rdn?dateShow=09-02-2022", "test.html") :
URL 'https://tge.pl/gaz-rdn?dateShow=09-02-2022': status was 'Failure when receiving data from the peer'
I've tried also disabling Use Internet Explorer library/proxy for HTTP in Rstudio Global Options but it didn't help. Another solution that I've tested was read_html() from rvest package - getting following error:
Error in open.connection(x, "rb") : Send failure: Connection was reset
Downloading data from other websites works fine though, with all considered methods.
Is there any way I can download data from this website with R?
Any kind of help or suggestion will be highly appreciated

HTTP error 403 when using jsonlite fromJSON in RStudio

library(jsonlite)
url <- "https://api.nftport.xyz/v0/nfts"
data <- fromJSON(url)
a <- as.data.frame(data)
I am new to API, JSON, and R in general. Would like to ask how do I go about building a connection with the API, and retrieving the JSON format, and converting it into a dataframe that I can use.
Have been facing this error.
Error in open.connection(con, "rb") : HTTP error 403.

Using the package RAdwords in an R script on a Unix server Error in rjson

I have the following script, which works perfectly fine, when I run it on my local PC:
library(RAdwords)
autX <- doAuth()
data <- getData(clientCustomerId='xxx-xxx-xxxx',
google_auth=autx
)
However, when I try to run the very same script on my Unix-Server, then I get this error message:
Error in rjson::fromJSON(RCurl::postForm("https://accounts.google.com/o/oauth2/token", :
STRING_ELT() can only be applied to a 'character vector', not a 'raw'
Question: What could be the reason and how can I fix it?
By the way:
I did copy the files .gitgnore and .google.auth.RData from the folder on my local PC, where I already did this authentification, to the directory on my server.
If I just type doAuth() alone I do not get an error message.
Issue:
getData()calls the function refreshToken() that updates the authentication token of the Google AdWords API. Within the function refreshToken the RCurl command returns a raw data file instead of a character file format. rjson::fromJSON returns an error that is solved with the addition of rawToChar().
Solution:
I created a patch of the function and updated the Github development version of RAdwords.
You can install the new package version with:
require(devtools)
install_github('jburkhardt/RAdwords')

Error message when using easyPubMed package in R

I am trying to use easyPubMed package in R to download content from PubMed in txt format. I am trying to run the following example:
dami_on_pubmed <- get_pubmed_ids("Damiano Fantini[AU]")
However, at this point I get the following error:
Error in url(myPubmedURL, open = "rb") : https:// URLs are not supported
How to solve this problem?
Thanks

Using jsonlite to interact with Spotify API in R

I am trying to extract Spotify data via the API
Using the below getAlbums Function:
getAlbums <- function(id,type="album",market="US") {
total <- jsonlite::fromJSON(paste0("https://api.spotify.com/v1/artists/",id,"/albums??&album_type=album"))$total
req <- jsonlite::fromJSON(paste0("https://api.spotify.com/v1/artists/",id,"/albums??offset=0&limit=",total,"&album_type=",type,"&market=",market))
return(req$items[,c("id","name","album_type","available_markets")])
}
I am getting the below error:
Error in open.connection(con, "rb") : HTTP error 400 Extracting Spotify Data
whereas i can successfully Authenticate for other parameters.

Resources