Guest User

Untitled

a guest
May 27th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. ## issues:
  2. ## -only gets replies within last ~7 days to the post due to public REST API limits
  3. ## -counts don't necessarily align with total replies via browser, perhaps due to private accounts (?)
  4.  
  5. get_replies <- function(tweetid){
  6. # get status information for given tweet
  7. t <- rtweet::lookup_statuses(statuses = tweetid)
  8.  
  9. # use search API to find all tweets directed to the poster
  10. # and keep only replied to that status
  11. z <- rtweet::search_tweets(q = paste0("to:",t$screen_name),
  12. sinceID = tweetid,
  13. n = 3200)
  14.  
  15. # keep only replies to tweetid status
  16. z <- subset(z, in_reply_to_status_status_id == tweetid)
  17.  
  18. # combine original tweet and replies
  19. z <- rbind(t, z)
  20.  
  21. # return dataframe
  22. return(z)
  23. }
  24.  
  25. tweetid <- "998970022474199041"
  26. z <- get_replies(tweetid)
  27.  
  28. # to get multiple; install purrr if you do not have it
  29. tweetid <- c("998662565222895618","998602734386458626")
  30.  
  31. z <- purrr::map_df(tweetid, get_replies)
Add Comment
Please, Sign In to add comment