我想使用R(关注者> 100000)查找用户的Twitter关注者的个人资料。尽管twitteR是一个很好的软件包,但在与高级别的关注者打交道时会遇到问题,因为需要实现 sleep 例程以避免超出速率限制。我在这里是个相对新手,想知道如何循环遍历关注者ID对象,以100个批次的方式输入关注者ID(因为这是Twitter API一次可以处理的最大值)?
编辑:添加代码
(推特)
图书馆(plyr)
maxTwitterIds = 100
sleep 时间= 500#秒
user<-getUser("[username]")
followers<-zz$getFollowerIDs()
ids_matrix = matrix(zz, nrow = maxTwitterIds, ncol = length(zz) / maxTwitterIds)
followers<-zz$getFollowerIDs()
#note: for smaller lists of followers it is possible to use the command "lookupUsers(zz) at this point
foll<-getTwitterInfoForListIds = function(id_list) {
return(lapply(id_list,
names <- sapply(foll,name)
sn<sapply(foll,screenName)
id<-sapply(foll,id)
verified<-sapply(foll,erified)
created<-sapply(foll,created)
statuses<-sapply(foll,statusesCount)
follower<-sapply(foll,followersCount)
friends<-sapply(foll,friendsCount)
favorites<-sapply(foll,favoritesCount)
location<-sapply(foll,location)
url<-sapply(foll,url)
description<-sapply(foll,description)
last_status<-sapply(foll,lastStatus)))
}
alldata = alply(, 2, function(id_set) {
info = getTwitterInfoForListIds(id_set)
Sys.sleep(sleeptime)
return(info)
})
最佳答案
也可以使用更新的rtweet
包来完成。
这里的示例:https://github.com/mkearney/rtweet
# Get followers
# Retrieve a list of the accounts following a user.
## get user IDs of accounts following CNN
cnn_flw <- get_followers("cnn", n = 75000)
# lookup data on those accounts
cnn_flw_data <- lookup_users(cnn_flw$user_id)
# Or if you really want ALL of their followers:
# how many total follows does cnn have?
cnn <- lookup_users("cnn")
# get them all (this would take a little over 5 days)
cnn_flw <- get_followers( "cnn", n = cnn$followers_count,
retryonratelimit = TRUE )
关于r - 在R中查找Twitter关注者,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9192698/