R Looping through list of follower to get ego network using twitteR package -


i trying network data on follows based on closed list of twitter accounts followed given user. is, given user a, i'd retrieve friends list , learn of friends follows each other.

the first issue had rate limit set twitter api, seemed solve using sys.sleep() function. although slow, used function shown below , worked fine first time. however, trying same info other users' friends list , keeps on giving me errors of type:

  • error in curl::curl_fetch_memory(url, handle = handle) : timeout reached
  • error http 503 , other errors. far i've tried 3 times in 3 different laptops , got different error each time. idea why may happening?

thanks lot in advance!

friendsnet <- function(tuser) {   require(twitter)    # if rate limit hit, wait 15 minutes   limit <- getcurratelimitinfo()[53,3]   print(paste("look limit", limit))   if (limit == 0) {     print("sleeping fifteen minutes")     sys.sleep(900)   }    # find user   tuser <- getuser(tuser)   print(tuser$screenname)    # empty dataframe   df <- null   print("empty data frame")    # names of friends   f <- lookupusers(tuser$getfriendids())   f.id <- sapply(f, id)   f.name <- sapply(f, screenname)   f2 <- as.data.frame(cbind(f.id, f.name))   print("list of friends")   print(head(f2))    (i in f2$f.name) {      # if rate limit hit, wait 15 minutes     limit <- getcurratelimitinfo()[53,3]     print(paste("look limit", limit))     if (limit == 0) {       print("sleeping fifteen minutes")       sys.sleep(900)     }     <- getuser(i)     friends.object <- lookupusers(a$getfriendids())     # convert list data frame     friends.id <- sapply(friends.object,id)     friends.name <- sapply(friends.object, screenname)     friends <- as.data.frame(cbind(friends.id, friends.name))      (j in f2$f.name) {       if (i != j) {         if ((j %in% friends$friends.name) == true) {           print(paste(i, "follows", j))           df <- rbind(df, data.frame(i, j))         }       }      }    }   return(df) } 


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -