Skip to content

Instantly share code, notes, and snippets.

@tts tts/gist:3002229
Created Jun 27, 2012

What would you like to do?
Returning the screen names of Twitter list members by the cursor
# Returning the screen names of members of a Twitter list by the cursor
# Example list!/niku_hooli/ylen-suomitop100-lista/
# Tuija Sonkkila
# 2012-06-27
# Twitter API
# Function adapted from
owner <- "niku_hooli"
list.slug <- "ylen-suomitop100-lista"
# Return screen names, and the next_cursor value
get_list_screen_names <- function(list.slug, owner, cursor) {
u <- paste("", list.slug,
"&owner_screen_name=", owner, "&cursor=", cursor, sep = "")
json <- getURL(u)
dat <- fromJSON(json)
m <- sapply(dat$users, function(d) d$screen_name)
cursor <- dat$next_cursor
# Put all in a list, and return
output <- list(cursor, m)
# Initialize a character vector for the names
p.all <- character(0)
# Initial cursor value
cursor <- -1
# Loop over the membership list until next_cursor=0, ie there is no more
while(cursor != 0) {
output <- get_list_screen_names(list.slug, owner, cursor)
# next_cursor is the first element in the list returned by the function
cursor <- output[[1]]
# all the other elements are screen names
p <- output[[-1]]
# append to previous names
p.all <- c(p, p.all)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.