-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_function.R
More file actions
38 lines (29 loc) · 1.13 KB
/
helper_function.R
File metadata and controls
38 lines (29 loc) · 1.13 KB
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
get_following <- function(tweet_id){
page <- 1
full <- list()
next_page_token <- ""
repeat {
cat("Grab Page:", page, "\n") # keep track of pages (not necessary but could be useful)
params <- list(`user.fields` = 'created_at',
`expansions` = 'pinned_tweet_id')
if (next_page_token == "")
{url_handle <-
glue::glue("https://api.twitter.com/2/users/{status_id}/following?max_results=1000",
status_id = tweet_id)}
else
{url_handle <- glue::glue("https://api.twitter.com/2/users/{status_id}/following?max_results=1000&pagination_token={page_token}", status_id = tweet_id, page_token = next_page_token)}
response <- httr::GET(url = url_handle,
httr::add_headers(.headers = headers))
obj <- httr::content(response, as = "text")
x <- rjson::fromJSON(obj)
full <- c(full, x$data %>% purrr::map_chr("id"))
if (is.null(x$meta$next_token))
{
cat("Final Page Counts Stops at:", page, "\n")
break
}
next_page_token <-x$meta$next_token
page = page + 1
}
return(unlist(full))
}