fetching large number of followers and followees i

2019-04-16 15:59发布

I am trying to get followers of XYZ and fetch them in descending order of their follower count (say we consider 400 of the top followers with respect of follower count). The code is--

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'm facing is that it doesn't give me the list of all followers. I surmise it's because of the 15 min API limit that twitter has. Anyway in which I can sort this out?

The second thing that I'm trying to do is get the followees(friends) of these followers and sort them in descending order of their follower count again. Let's say we take the top 100 followees with respect to the follower count.

The follow-up code which contains all these followees of followers in a data frame is (the column names of data frame are: odd numbered columns representing users and even numbered columns representing the count of followees' followers):

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'm getting over here is:

[1] "Unauthorized"
Error in twInterfaceObj$doAPICall(cmd, params, method, ...) : 
  Error: Unauthorized

I'm using Sys.sleep(61) so that I don't make more than 1 search per minute (since twitter API limit is 15 for 15 mins, so I guess this works fine).

The session info:

> 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 a novice in R and require this manipulation to work on the interest-graph building. So, I would be glad if anyone can help me with this.

Thanks a lot for any help in advance.

标签: r twitter
0条回答
登录 后发表回答