0

我编写了以下脚本,每 15 分钟使用rtweet. 但是,在脚本运行完成后,我发现朋友 ID 在固定间隔后重复。例如,第 1、280001 和 560001 行具有相同的 ID。第 2、280002 和 560002 行具有相同的 ID,依此类推。我想知道我是否next_cursor对 API 的理解有误。

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)
}

任何帮助将不胜感激。

4

1 回答 1

1

你没有做错任何事。从文档中

此订单可能会出现未宣布的更改和最终的一致性问题

For very large lists, the API simply won't return all the information you want.

于 2019-10-18T08:52:10.827 回答