OAuth的与R中的Twitter流API(使用RCurl) [英] Oauth with Twitter Streaming API in R (using RCurl)

查看:602
本文介绍了OAuth的与R中的Twitter流API(使用RCurl)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到R中使用RCurl Twitter的流API,并且还能够过滤关键字。然而,在Twitter的API 1.1版授权新的限制使用RCurl困难的决策。

I would like to connect to Twitter's Streaming API using RCurl in R, and also be able to filter keywords. However, new restrictions on authorization in Twitter API v1.1 is making using RCurl difficult.

在,code可能是这样的,从此页

Before, code could go something like this taken from this page:

 getURL("https://stream.twitter.com/1/statuses/filter.json", 
   userpwd="Username:Password",
   cainfo = "cacert.pem",
   write=my.function,
   postfields="track=bruins")

但现在,Twitter的新的API让用户通过OAuth认证。我有一个令牌和秘密,我只是需要把它放在这个code授权。

But now, Twitter's new API is making users authorize with OAuth. I have a token and secret, I just need to place it in this code for authorization.

谢谢!

推荐答案

您可以用pacakge做到 ROAuth 。我假设你已经注册与Twitter您的应用程序,并有一个API密钥。我拼凑此一并从其他问题上堆栈溢出(这个问题和相关答案还包含一些链接到其他的问题作出贡献)和的对于包中的文件 ROAuth 微博

You can do it with pacakge ROAuth. I assume you have registered your app with Twitter and have an API key. I pieced this together from other questions on Stack Overflow (that question and associated answers also contains some links to other contributing questions) and the documentation for package ROAuth and twitteR.

library(RCurl)
library(twitteR)
library(ROAuth)

requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL = "http://api.twitter.com/oauth/access_token"
authURL = "http://api.twitter.com/oauth/authorize"
consumerKey = "myconsumerkeystring"
consumerSecret = "myconsumersecretstring"
Cred <- OAuthFactory$new(consumerKey=consumerKey,
                             consumerSecret=consumerSecret,
                             requestURL=requestURL,
                             accessURL=accessURL, 
                             authURL=authURL)
    #The next command provides a URL which you will need to copy and paste into your favourite browser
    #Assuming you are logged into Twitter you will then be provided a PIN number to type into the R command line
Cred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl") )
    # Checks that you are authorised
registerTwitterOAuth(Cred)

我相信,使用流API是由包 streamR

心连心

这篇关于OAuth的与R中的Twitter流API(使用RCurl)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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