2
我想下載推文(不搜索特定問題)。我想你的建議是:Twitter,錯誤:401訪問'/1/statuses/sample.json'。原因:未授權
curlPerform(url = https://stream.twitter.com/1/statuses/sample.json -u USER:PASSWORD -o "somefile.txt"
# 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",
cainfo = "cacert.pem",
write=WRITE_TO_FILE)
只有我壓抑「userpwd =「用戶名:密碼:」我得到的結果,這是一個包含以下信息的文本文件:
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1/statuses/sample.json'. Reason:
<pre> Unauthorized</pre>
我期待R內部完全停留,並需要使用Windows。如何解決這個問題有什麼建議?提前
感謝
謝謝。我用我的Twitter用戶名和密碼替換了用戶名和密碼,但不幸的是我沒有解決問題。我得到了:function(x){if(nchar(x)> 0){write.table(x,file =「twitter_stream_capture.txt」,append = TRUE,row.names = FALSE,col.names = FALSE)read。表格(「Twitter Stream Capture.txt」)1 \ n
\ n \ n我上面發佈的代碼完全適合RCurl_1.6-10.1。 – jbaums 2012-02-15 17:14:53
謝謝。我意識到我的是RCurl_1.91-1.1 bitops_1.0-4.1。它應該是一個問題嗎?或者可能是我試圖'訪問'file ='twitter_stream_capture.txt'中的數據? (我用'readHTMLTable')? – 2012-02-22 12:55:05