Oauth with Twitter Streaming API in R (using RCurl)

后端 未结 1 1306
独厮守ぢ
独厮守ぢ 2020-12-09 00:33

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

相关标签:
1条回答
  • 2020-12-09 01:05

    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)
    

    I believe that use of the streaming API is handled by the package streamR

    HTH

    0 讨论(0)
提交回复
热议问题