By choosing a large number of followers and followers in R
I'm trying to get XYZ followers and get them in descending order of their number of trackers (let's say we consider the top 400 followers in relation to the number of trackers). Code -
library(twitteR)
user <- getUser("XYZ")
followers <- user$getFollowers()
b <- twListToDF(followers)
f_count <- as.data.frame(b$followersCount)
u_id <- as.data.frame(b$id)
u_sname <- as.data.frame(b$screenName)
u_name <- as.data.frame(b$name)
final_df <- cbind(u_id,u_name,u_sname,f_count)
sort_fc <- final_df[order(-f_count),]
colnames(sort_fc) <- c('id','name','s_name','fol_count')
The first problem I ran into is that it doesn't give me a list of all followers. I assume this is due to the 15 minute API limitation that twitter has. Anyway, when can I sort this out?
The second thing I'm trying to do is get the followers (friends) of those followers and sort them in descending order of their number of followers. Let's say we take the top 100 followers in terms of adherence counting.
The following code, which contains all these followers of the followers in the dataframe (the column names of the dataframe are odd-numbered columns representing users and even columns representing the followers counts):
alpha <- as.factor(sort_fc[1:400,]$s_name)
user_followees <- rep(list(list()),10)
fof <- rep(list(list()),10)
gof <- rep(list(list()),10)
m <- data.frame(matrix(NA, nrow=100, ncol=800))
colnames(m) <- sprintf("%d",1:80)
for(i in 1:400)
{
user <- getUser(alpha[i])
Sys.sleep(61)
user_followees[[i]] <- user$getFriends(n=100)
fof[[i]] <- twListToDF(user_followees[[i]])$screenName
gof[[i]] <- twListToDF(user_followees[[i]])$followersCount
j <- 2*i-1
k <- 2*i
m[,j] <- fof[[i]]
m[,k] <- gof[[i]]
c <- as.vector(m[,j])
d <- as.vector(m[,k])
n <- cbind(c,d)
sort <- n[order(-d),]
m[,j] <- sort[,1]
m[,k] <- sort[,2]
}
The error I am getting here:
[1] "Unauthorized"
Error in twInterfaceObj$doAPICall(cmd, params, method, ...) :
Error: Unauthorized
I am using Sys.sleep (61) so I donβt do more than 1 search per minute (since the twitter API limit is 15 for 15 minutes, so I think this works great).
Session Information:
> sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] twitteR_1.1.6 rjson_0.2.12 ROAuth_0.9.3 digest_0.6.3 RCurl_1.95-4.1
[6] bitops_1.0-5
I am new to R and require this manipulation to work on plotting interests. So I would be glad if someone can help me with this.
Thanks a lot for any help in advance.
source to share
No one has answered this question yet
See similar questions:
or similar: