SSL certificate failed for twitteR in R

2019-07-21 08:17发布

我知道类似的问题已经再次问道。 不过,我尝试了一切,我发现这里和谷歌并没有什么似乎为我工作。

我的代码如下:

reqURL <- "http://api.twitter.com/oauth/request_token"
accessURL <- "http://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"
consumerKey <- "xxxxxxxxxxx"
consumerSecret <- "xxxxxxxxxxxxxxxxxxx"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
                         consumerSecret=consumerSecret,
                         requestURL=reqURL,
                         accessURL=accessURL,
                         authURL=authURL)
twitCred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
registerTwitterOAuth(twitCred)

在这里,我得到: [1] TRUE

但是,如果我试试这个: tweets = searchTwitter('blabla', n=1500)

我收到以下错误: [1] "SSL certificate problem, verify that the CA cert is OK. Details:\nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" Error in twInterfaceObj$doAPICall(cmd, params, "GET", ...) : Error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [1] "SSL certificate problem, verify that the CA cert is OK. Details:\nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" Error in twInterfaceObj$doAPICall(cmd, params, "GET", ...) : Error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

下面是我的电脑包和版本:

sessionInfo()R版本2.15.1(2012-06-22)平台:I386-PC-的mingw32 / I386(32位)

locale:
[1] LC_COLLATE=Greek_Greece.1253  LC_CTYPE=Greek_Greece.1253   
[3] LC_MONETARY=Greek_Greece.1253 LC_NUMERIC=C                 
[5] LC_TIME=Greek_Greece.1253    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ROAuth_0.9.2   digest_0.6.2   twitteR_1.1.0  rjson_0.2.12  
[5] RCurl_1.95-4.1 bitops_1.0-5  

loaded via a namespace (and not attached):
[1] tools_2.15.1

任何帮助将是非常有用的!

Answer 1:

先做下面,然后运行你的代码:

library(RCurl) 

# Set SSL certs globally
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))

这通常纠正您遇到的问题有关。

编辑(2014年8月): 或者更好的是,尝试使用HTTR软件包,而不是(这是RCurl与对您有用设置默认选项友好包装)



Answer 2:

我终于得到了解决,请尝试此方法。 这是很容易

library(devtools)
install_github("twitteR", username="geoffjentry")
library(twitteR)

api_key = "aaa"
api_secret = "bbb"
access_token = "ccc"
access_token_secret = "ddd"
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)


Answer 3:

您可能需要更新您的cacert.pem文件。 见这里和这里的链接,这方面的其他问题。 我认为这并没有为其他人使用工作download.file()但是这可能会直接使用curl。 您可以更新包文件,如下所示:

system( paste0( "curl http://curl.haxx.se/ca/cacert.pem -o " , tempdir() , "/cacert.pem" ) )
#Then you can use it like so
twitCred$handshake( cainfo = paste0( tempdir() , "/cacert.pem" ) )

HTH



文章来源: SSL certificate failed for twitteR in R