我正在尝试使用rtweet函数get_followers从大量用户那里收集关注者信息。为了减少等待时间,我的环境中有三个不同的令牌。但是,我不确定如何使它们迭代。
我有以下代码。第一部分(包括第一个循环)正常但非常缓慢地工作(好像仅在使用一个令牌)。第二个循环(我确定写错了)给出了一个错误。
twitter_token1 <- c(
create_token(app = "XXXXX",
consumer_key = "XXXXXXXX",
consumer_secret = "XXXXXXXXXXX")
)
twitter_token2 <- c(
create_token(app = "XXXXXXXXX",
consumer_key = "XXXXXXXX",
consumer_secret = "XXXXXXXXXXXXXXX")
)
twitter_token3 <- c(
create_token(app = "XXXXXXXXX",
consumer_key = "XXXXXXXX",
consumer_secret = "XXXXXXXXXXXXXXX")
)
tokens <- c(token1, token2, token3)
users<– c("realDonaldTrump",
"GOPLeader",
"SteveScalise","USATODAY",
"WSJbusiness",
"WSJbreakingnews")
for (i in seq_along (users)){
for (j in seq_along(tokens)){
list_followers <- get_followers(users[i], n= "all", retryonratelimit = T, token = tokens[j])
}
}
#I have also tried:
for (i in seq_along (USall)){
for (j in seq_along(info_USall$followers_count)){
list_USfollowers <- get_followers(USall[i], n= info_USall$followers_count[j], retryonratelimit = T)
if (i %% 15L==0L) {
limit <- lapply(tokens, rate_limit, "get_followers")
for (h in seq_along(tokens)){
sys.call(tokens[h], which(limit[remaining]>0))
}
}
}
}
#However I am sure this loop is not correctly written as I'm not very familiar with the sys.call function.
第一个循环正确运行,并给了我一个关注者ID的列表。但是,它会停止15分钟,并且不会迭代令牌。