Created
September 20, 2013 15:23
-
-
Save emhart/6639202 to your computer and use it in GitHub Desktop.
How use use the twitter api with ROAuth and twitteR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(twitteR) | |
require(ggplot2) | |
library(ROAuth) | |
library(plyr) | |
### See this post on how to get your key and secret to put | |
### in below as strings: https://dev.twitter.com/discussions/631 | |
reqURL <- "https://api.twitter.com/oauth/request_token" | |
accessURL <- "http://api.twitter.com/oauth/access_token" | |
authURL <- "http://api.twitter.com/oauth/authorize" | |
consumerKey <- "YourConsumerKey" | |
consumerSecret <- "YourConsumerSecret" | |
twitCred <- OAuthFactory$new(consumerKey=consumerKey, | |
consumerSecret=consumerSecret, | |
requestURL=reqURL, | |
accessURL=accessURL, | |
authURL=authURL) | |
### Run this line and follow the instructions | |
twitCred$handshake() | |
### This will tell you if you're authorized, it should return true | |
registerTwitterOAuth(twitCred) | |
### Do your thing, in this case make a histogram of handle names | |
### and hashtag use. | |
rez <- searchTwitter("#ubcbdg",n=100) | |
users <- ldply(rez,function(x) return(x$screenName)) | |
ggplot(users,aes(x=V1))+geom_histogram()+theme(axis.text.x = element_text(angle = 45, hjust = 1))+ylab("Count of tweets using #ubcbdg")+xlab("Twitter handle") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems to be common on Windows to have to use the
cainfo
argument for any function that usesGET
:There's more info on the issue on this SO question: http://stackoverflow.com/questions/9916283/twitter-roauth-and-windows-register-ok-but-certificate-verify-failed