我想使用 R 查找用户的 Twitter 关注者的个人资料(关注者 > 100000)。尽管 twitteR 是一个很棒的软件包,但它在处理大量关注者时存在问题,因为人们需要实施睡眠例程以避免超过速率限制。我是一个相对新手,想知道如何循环遍历关注者 ID 对象,以 100 个为批次输入关注者 ID(因为这是 Twitter API 一次可以处理的最大值)?
编辑:添加代码
(推特)
图书馆(plyr)
最大 TwitterId = 100
睡眠时间 = 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)
})