且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用R连接到Twitter Streaming API

更新时间:2022-10-31 10:20:18

I was able to figure out the basics, hopefully this helps.

#==============================================================================
# Streaming twitter using RCURL
#==============================================================================
library(RCurl)
library(rjson)

# set the directory
setwd("C:\\")

#### redirects output to a file
WRITE_TO_FILE <- function(x) {

     if (nchar(x) >0 ) {
          write.table(x, file="Twitter Stream Capture.txt", append=T, row.names=F, col.names=F)
     }

}

### windows users will need to get this certificate to authenticate
download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")

### write the raw JSON data from the Twitter Firehouse to a text file
getURL("https://stream.twitter.com/1/statuses/sample.json", 
       userpwd=USER:PASSWORD,
       cainfo = "cacert.pem", 
       write=WRITE_TO_FILE)

相关阅读

技术问答最新文章