Unable to pull JSON data from stats.nba.com - r

I've been having some difficulty getting data from stats.nba.com. I've been able to pull info pretty easily in the past, so wanted to see if you guys noticed any issues in my code or if you're running into the same problems.
I'm using rjson.
library(rjson)
url <- "https://stats.nba.com/stats/boxscoresummaryv2?GameID=0041800406"
a <- fromJSON(file = url)
When I run this, I get:
Error in file(con, "r") :
cannot open the connection to 'https://stats.nba.com/stats/boxscoresummaryv2?GameID=0041800406'
In addition: Warning message:
In file(con, "r") :
URL 'https://stats.nba.com/stats/boxscoresummaryv2?GameID=0041800406': status was 'Failure when receiving data from the peer'
I can, however, see the data in JSON format by following the request url. Anybody notice any mistakes I'm making?

The following code can read the json file into a list object.
library(jsonlite)
read_json("https://stats.nba.com/stats/boxscoresummaryv2?GameID=0041800406")

Not really a specific answer; think it was due to some issue with my firewall. Was able to get everything to work on a different network.

Related

ZendeskR Producing the following error when trying to connect to api

I am fairly new to using APIs and trying to use the zendesk API now through R using the ZendeskR package. I belive I have connected to it however I keep getting the following error whenever I try to query it.
Here is my code:
library(zendeskR)
library(rjson)
zendesk(username, password, url)
ticket <- getTicket('20150')
The username, password and url are all variables that I have assigned the correct values.
The following error that I get when I run it is this:
Error in function (type, msg, asError = TRUE) :
error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
Please help as I am unsure on what this error means or what I am doing wrong.
Thanks.
TLS v1.1 is no longer accepted by Zendesk, please use TLS v1.2.

client error (400) using gsheet2tbl to get Google Sheet data

Since Rcurl no longer works for importing data into R from Google Sheets, I have been using gsheet2tbl.
This has been working well but today I was trying to download from a recently created Google Sheet and I received the following error:
url2<-"https://docs.google.com/spreadsheets/d/.../edit?usp=sharing"
d <- gsheet2tbl(url2, sheetid = 0)
Error in parse.response(r, parser, encoding = encoding) :
client error: (400) Bad Request
I double checked and everything is working just fine with my previously created Google Sheets.
Does anyone have any thoughts on how I can troubleshoot this issue?
Thanks very much,
Matt
There's a new package for reading from Google sheets... https://github.com/jennybc/googlesheets
I find that it's fantastic for this sort of work. Give it a shot...
devtools::install_github("jennybc/googlesheets")
# run this and it will ask for user authentication...
gs_ls()
gs_read(ws = "Your worksheet")

R - Accesing Google Big Query with R. Authetication failed

I am trying to access Google Big Query with R, using the 'assertthat' and 'bigrquery' packages, following these instructions:
http://thinktostart.com/using-google-bigquery-with-r/#comment-22450
http://www.lunametrics.com/blog/2014/06/25/google-analytics-data-mining-bigquery-r/
The issue comes at the authentication step, I get directed to a code in the webbrowser, and when I paste the code in the terminal the following error appears:
Enter authorization code:
####CODE GOES HERE#####
Error en function (type, msg, asError = TRUE) :
Could not resolve host: accounts.google.com
I think that one possible issue is that we are behind a corporate firewall. While we do have access to the internet and I can install R packages, if I ping google.com from the terminal, I get an error. But I would like to know if any of you have found a solution to this kind of problem.
Thank you very much for reading this post. Any help is appreciated.
I found a solution to the issue. It was related to the corporate proxies. If I use the wifi for visitors I can run queries.

How to avoid "too many redirects" error when using readLines(url) in R?

I am trying to mine news articles from various sources by doing
site = readLines(link)
link being the url of the site I am trying to download. Most of the time this works but with some specific sources I get the error:
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") : too many redirects, aborting ...
Which I'd like to avoid but so far I had no success in doing so.
Replicating this is quite easy as virtually none of the New York Times links work
e.g. http://www.nytimes.com/2014/08/01/us/politics/african-leaders-coming-to-talk-business-may-also-be-pressed-on-rights.html
It seems like the NYT site forces redirects for cookie and tracking purposes. Looks like the built-in URL reader isn't able to deal with them correctly (not sure if it supports cookies which is probably the problem).
Anyway, you might consider using the RCurl package to access the file instead. Try
library(RCurl)
link = "http://www.nytimes.com/2014/08/01/us/politics/african-leaders-coming-to-talk-business-may-also-be-pressed-on-rights.html?_r=0"
site <- getURL(link, .opts = curlOptions(
cookiejar="", useragent = "Mozilla/5.0", followlocation = TRUE
))

How to access a web service that requires authetication [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Reading information from a password protected site
I have a webservice that provides data in csv form, based on the url you use to access it. i.e. http://sever.com/parameter1 returns a csv for parameter 1, http://sever.com/parameter1 returns a csv for parameter 2, etc. When I first access the site in my browser, I type in a username and password and can then access any data I want.
The problem arises when I try to import that data into R. I tried this function:
readLines('http://sever.com/parameter1')
But got the following error:
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") : cannot open: HTTP status was '401 Unauthorized'
Of course, this is because R doesn't know to pass my username and password along with the request. How do I define these additional parameters in R? Is there any way to add a cookie to the request or something?
Thank you.
/edit: The answer here (different question wording wasn't picked up by SO) worked for me:
Reading information from a password protected site
If anyone else has any other advice, please let me know.
Why don't you use curl to grab the file? That way you can set http headers for username and password:
curl --user name:password http://www.example.com
There is a curl library for R
http://curl.haxx.se/libcurl/r/

Resources