Twitter,错误:401 访问“/1/statuses/sample.json”。原因:未经授权

发布于 2025-01-05 01:39:03 字数 1195 浏览 1 评论 0原文

我想下载推文(不搜索特定问题)。我尝试了你的建议:

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。有关如何操作的任何建议 解决这个问题?

提前感谢您

I want to download tweets (without searching an specific question). I tried your advice:

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)

Only if I suppress 'userpwd="Username:Password' I get a result, which is a text file containing the following information:

<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>

I am looking to stay completely within R and need to use Windows. Any advice on how to solve this problem?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沩ん囻菔务 2025-01-12 01:39:03

尝试使用 userpwd 参数指定用户名和密码:

library(RCurl)

WRITE_TO_FILE <- function(x) {
  if (nchar(x) > 0) {
    write.table(x, file='twitter_stream_capture.txt', append=TRUE, 
                row.names=FALSE, col.names=FALSE)
  }
}

download.file(url='http://curl.haxx.se/ca/cacert.pem', destfile='cacert.pem')

getURL('https://stream.twitter.com/1/statuses/sample.json', 
       userpwd='username:password', cainfo='cacert.pem',
       write=WRITE_TO_FILE)

getURL 中的 usernamepassword 替换为有效的 Twitter 用户名和密码。

Try specifying the username and password with the userpwd argument:

library(RCurl)

WRITE_TO_FILE <- function(x) {
  if (nchar(x) > 0) {
    write.table(x, file='twitter_stream_capture.txt', append=TRUE, 
                row.names=FALSE, col.names=FALSE)
  }
}

download.file(url='http://curl.haxx.se/ca/cacert.pem', destfile='cacert.pem')

getURL('https://stream.twitter.com/1/statuses/sample.json', 
       userpwd='username:password', cainfo='cacert.pem',
       write=WRITE_TO_FILE)

Replace username and password in getURL with a valid Twitter username and password.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文