我编写了以下脚本,每15分钟使用rtweet
批量提取75,000个Twitter用户的朋友(在此示例中为“ barackobama”)(每个API调用5000个朋友x 15个API调用)。但是,在脚本运行完成后,我发现朋友ID在固定间隔后重复出现。例如,行1、280001和560001具有相同的ID。第2行,280002和560002具有相同的ID,依此类推。我想知道我是否错误地理解了API中的next_cursor
。
u = "barackobama"
n_friends = lookup_users(u)$friends_count
curr_page = -1
fetched_friends = 0
i = 0
all_friends = NULL
while(fetched_friends < n_friends) {
if(rate_limit("get_friends")$remaining == 0) {
print(paste0("API limit reached. Reseting at ", rate_limit("get_friends")$reset_at))
Sys.sleep(as.numeric((rate_limit("get_friends")$reset + 0.1) * 60))
}
curr_friends = get_friends(u, n = 5000, retryonratelimit = TRUE, page = curr_page)
i = i + 1
all_friends = rbind(all_friends, curr_friends)
fetched_friends = nrow(all_friends)
print(paste0(i, ". ", fetched_friends, " out of ", n_friends, " fetched."))
curr_page = next_cursor(curr_friends)
}
任何帮助将不胜感激。