使用rtweet获得超过Twitter API允许的朋友数量

问题描述 投票:0回答:1

我编写了以下脚本,每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)
}

任何帮助将不胜感激。

r twitter rtweet
1个回答
0
投票

您没有做错任何事情。从the documentation

此订单可能会进行未经通知的更改,并且最终一致性问题

对于非常大的列表,API根本不会返回您想要的所有信息。

© www.soinside.com 2019 - 2024. All rights reserved.