使用 R 发送推文 [英] Using R to send tweets

查看:18
本文介绍了使用 R 发送推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个月前,我在一次演示中看到了一个来自 R 的推文的可爱演示.演示者使用的暂存代码在这里:

I saw a cute demonstration of tweeting from R in a presentation some months ago. The scratch code used by the presenter is here:

http://www.r-bloggers.com/twitter-from-r%E2%80%A6-sure-why-not/

代码简短而甜蜜:图书馆(RCurl")opts <- curlOptions(header = FALSE,userpwd = "用户名:密码", netrc = FALSE)

the code is short and sweet: library("RCurl") opts <- curlOptions(header = FALSE, userpwd = "username:password", netrc = FALSE)

tweet <- function(status){
  method <- "http://twitter.com/statuses/update.xml?status="
  encoded_status <- URLencode(status)
  request <- paste(method,encoded_status,sep = "")
  postForm(request,.opts = opts)
}

使用此功能,您只需使用更新功能即可发送推文:

With this function, you can send a tweet simply by using the update function:

tweet("This tweet comes from R! #rstats")

我认为这可能是宣布长期工作完成的有用方式.我试图在我的机器上运行它,但出现了一些错误:

I thought that this could be a useful way of announcing when long jobs are completed. I tried to run this on my machine, and I got some error:

[1] "\n\n 不支持基本身份验证\n\n"attr(,"内容类型")字符集应用程序/xml"utf-8"警告信息:在 postForm(request, .opts = opts) 中:没有输入传递给表单

[1] "\n\n Basic authentication is not supported\n\n" attr(,"Content-Type") charset "application/xml" "utf-8" Warning message: In postForm(request, .opts = opts) : No inputs passed to form

我想知道 twitter 端是否有一些更改,导致此代码产生此错误?我不太了解让 R 与网页交谈,因此非常感谢任何指导!!

I'm wondering if there has been some changes on the twitter end of this, that make this code produce this error? I don't know too much about getting R to talk to webpages, so any guidance is much appreciated!!

E

推荐答案

是的,基本身份验证方案已于 2010 年 8 月 16 日禁用.您需要将其设置为使用 OAuth.不幸的是,这远没有使用基本身份验证那么简单

Yes, the basic authentication scheme was disabled on the 16th August 2010.. You'll need to set it up to use OAuth. Unfortunately that is not nearly as simple as using basic authentication

请参阅此 twitter wiki 页面了解更多信息和 这个 StackOverflow 问题关于 R 的 OAuth.

See this twitter wiki page for more information and this StackOverflow question about OAuth for R.

这篇关于使用 R 发送推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆