Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

58 lines (42 sloc) 1.384 kB
#This R (helper) function queries the Twitter Search API
#
#https://dev.twitter.com/docs/api/1/get/search
#
#by hashtags.
#
#It returns co-occurent user mentions for each tweet (id)
#and user as data.frame for up to 1.500 Tweets.
#
#NB: Provision of query without hashtag "#"
#dependencies
require(RJSONIO)
require(RCurl)
#function
hash.search.rt <- function (query) {
url <- paste("http://search.twitter.com/search.json?q=%23",query,
"&rpp=50&include_entities=true",sep="")
my.data <- data.frame()
df.tmp <- data.frame()
for (k in 1:30) {
url.d <- paste(url,"&page=",k,sep="")
my.json <- fromJSON(getURL(url.d), nullValue = NA)
if(length(my.json$results) == 0)
break
else
for (i in seq_along(my.json$results)){
id <- my.json$results[[i]]$id
from_user <- my.json$results[[i]]$from_user
user.Ment <- my.json$results[[i]]$entities$user_mentions
user <- c()
for (j in seq_along(user.Ment)) {
user.tmp <- user.Ment[[j]]$screen_name
user <- c(user, user.tmp)
}
id <- rep(id,times=length(user))
from_user <- rep(from_user,times=length(user))
df.tmp <- cbind(id, from_user, user)
my.data <- rbind(my.data, df.tmp)
}
}
return(my.data)
}
Jump to Line
Something went wrong with that request. Please try again.