surfer
surfer

Reputation: 21

how to handle sending request for user details from twitter API multiple times in R. It gives an error and sometimes it gives empty list in return

I have a list of more than 1000 twitter handle and I am using getUser() function from the twitteR package. But after around 20 success returns I get an error saying empty list passed.

Can anyone help me in figuring out what is the problem. Also when I request for the same user individually, I get the result.

The error is: empty list passed to twListToDF

library(twitteR)
#here twitter_dig_aud is the list of 1000 or more twitter handles

twitter_data <- lookupUsers(twitter_dig_aud[start:end,])
twitter_data <- twListToDF(twitter_data)
twitter_data <- subset(twitter_data, protected == FALSE)
twitter_data <- data.frame(twitter_data$screenName)

for(i in 1:nrow(twitter_data)){
  print(paste("Row number ", i , " of ", nrow(twitter_data)))
  id <- twitter_data[i, 1]
  print(as.vector(id))
  ab <- user_following(id)
}


    user_following <- function(id){
  #here at this level I am authenticating my twitter connection
  library(twitteR)
  folw_details <- getUser(id)

  if(folw_details$getFriendsCount() == 0){
    return()
  } else{
    #get followeres details

    #i get error at this stage saying empty list passed to twListToDF
    friends <- twListToDF(folw_details$getFriends())

    #Id <- id
    friends <- friends$screenName
    return(friends)        
    }
   }

Please help me, what is the problem in this scenario. I am facing the same issue while applying for other details such as follower count and following count.

Upvotes: 0

Views: 709

Answers (1)

surfer
surfer

Reputation: 21

I read a lot and tried multiple ways to figure out and finally found out something.It is the twitter API which allow only 20-30 queries per 15 min.

So I allowed my program to sleep for 15 minutes and it is working fine now.

After program sleep, I authorized my twitter connection.

I used following code:

print("Process sleeps for 15 mins due to twitter API security issues and then it will continue")
    Sys.sleep(900)
    authorise()

Yes, but the drawback is that the processing speed is very slow.

Thank you for your efforts @symbolrush

Upvotes: 1

Related Questions