File: lists_subscribers.R

package info (click to toggle)
r-cran-rtweet 2.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,068 kB
  • sloc: sh: 13; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,468 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#' Get subscribers of a specified list.
#'
#' @inheritParams TWIT_paginate_cursor
#' @inheritParams stream
#' @param list_id required The numerical id of the list.
#' @param slug,owner_user The list name (slug) and owner.
#' @family lists
#' @family users
#' @export
#' @references <https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers>
lists_subscribers <- function(list_id = NULL,
                              slug = NULL,
                              owner_user = NULL,
                              n = 5000,
                              cursor = "-1",
                              parse = TRUE,
                              retryonratelimit = NULL,
                              verbose = TRUE,
                              token = NULL) {

  params <- lists_params(
    list_id = list_id,
    slug = slug,
    owner_user = owner_user
  )

  r <- TWIT_paginate_cursor(token, "/1.1/lists/subscribers", params,
    n = n,
    cursor = cursor,
    retryonratelimit = retryonratelimit,
    verbose = verbose,
    page_size = if (n >= 5000) 5000 else n,
    get_id = function(x) x$users$id_str
  )

  if (parse) {
    r <- parse_lists_users(r)
  }
  r
}

parse_lists_users <- function(x) {
  users <- lapply(x, function(x) x$users)
  dfs <- lapply(users, wrangle_into_clean_data, type = "user")
  dfs <- lapply(dfs, tibble::as_tibble)
  df <- do.call(rbind, dfs)

  copy_cursor(df, x)
}