Skip to content

Commit

Permalink
Retry after rate limit is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
llrs committed Sep 1, 2022
1 parent 7b187e0 commit e830de5
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 109 deletions.
14 changes: 7 additions & 7 deletions R/followers.R
Expand Up @@ -11,12 +11,12 @@
#' if (auth_has_default()) {
#' users <- get_followers("_R_Foundation")
#' users
#'
#'
#' # use `cursor` to find the next "page" of results
#' more_users <- get_followers("_R_Foundation", cursor = users)
#'
#' }
#' @return A tibble data frame with one column named "from_id" with the
#' @return A tibble data frame with one column named "from_id" with the
#' followers and another one "to_id" with the user used as input.
#' @export
get_followers <- function(user, n = 5000,
Expand All @@ -26,25 +26,25 @@ get_followers <- function(user, n = 5000,
verbose = TRUE,
token = NULL,
page = lifecycle::deprecated()) {

if (lifecycle::is_present(page)) {
lifecycle::deprecate_warn("1.0.0", "get_followers(page)", "get_followers(cursor)")
cursor <- page
}

stopifnot(is.atomic(user), isTRUE(length(user) == 1))

params <- list(stringify_ids = TRUE)
params[[user_type(user)]] <- user

results <- TWIT_paginate_cursor(token, "/1.1/followers/ids", params,
page_size = if(n >= 5000) 5000 else n,
results <- TWIT_paginate_cursor(token, "/1.1/followers/ids", params,
page_size = if (n >= 5000) 5000 else n,
n = n,
cursor = cursor,
retryonratelimit = retryonratelimit,
verbose = verbose
)

if (parse) {
df <- tibble::tibble(from_id = unlist(lapply(results, function(x) x$ids)),
to_id = user)
Expand Down

0 comments on commit e830de5

Please sign in to comment.