I am trying to use twitteR's searchTwitter()
function with a curl proxy, but I'm getting a JSON-related error. I see that a lot of people have gotten this same JSON error. But I believe the cause of mine is different, so I will try to be specific in my question.
I have properly set up the OAuth connection with Twitter's API. I am on Windows, and using the latest version of R and all the packages. I am using a proxy because of my company's firewall. I am using RCurlOptions
to configure the proxy. I also bring in RJSONIO. The code runs fine outside of my company's firewall when I don't have to configure the proxy.
library(RCurl)
library(twitteR)
library(RJSONIO)
options(RCurlOptions = list(
proxy ="proxy.mycompany.net:8080",
proxyuserpwd="USERNAME:PASSWORD",
cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
load("OAuth.RData") #Load in my OAuth credentials object
registerTwitterOAuth(cred)
geico.tweets <- searchTwitter('@geico', n = 2)
This is the error I get:
Error in twFromJSON(out) :
Error: Malformed response from server, was not JSON.
I know it is not an issue of Twitter returning a character that can't be properly parsed by R, because I can't even bring in any single tweet (plus, it works fine outside the firewall).
This link suggests it may be caused by my use of RCurl: https://github.com/omegahat/RCurl/issues/1
His explanation is the JSON is messed up because of my use of RCurl. The \\
is converted to \
by R_mapString
, which is called only if the data includes Unicode character. That's about as much as I understand. He also mentions a .mapUnicode
argument.
Is there some parameter in RCurlOptions
I can configure that will fix this issue? Thanks.