我确信每个人都知道Twitter的API的局限性以及无法获得给定推文的回复数量。
我发布此信息之后,我正试图遍历指定帐户的所有关注者,并回顾他们发布过的所有时间,以及这些推文是否转到原始帐户。
我相信这将解决只能使用搜索功能获得最后几周价值的推文的问题。
下面的代码不起作用,任何帮助都会非常有用!我知道Python可以做到这一点,但如果可能的话,我想要一个R解决方案。
library(rtweet)
library(plyr)
library(dplyr)
##set name of tweeter to look at (this can be changed)
targettwittername <- "realDonaldTrump"
##get this tweeter's timeline
tmls <- get_timeline(targettwittername, n=3200, retryonratelimit=TRUE)
##get their user id
targettwitteruserid <- as.numeric(select(lookup_users(targettwittername), user_id))
##get ids of their tweets
tweetids <- select(tmls, status_id)
tweetids <- transform(tweetids, status_id_num=as.numeric(status_id))
##get list of followers (who are most likely to reply)
targetfollowers <- get_followers(targettwittername, retryonratelimit=TRUE)
master_reply_counts <-data.frame(reply_to_status_id_num=integer(),n=integer())
getfollowersreplies <- function(follower){
follower <- as.numeric(filter(targetfollowers, user_id==follower))
followertl <- get_timeline(user = follower, n=3200, retryonratelimit=TRUE)
followertl <- filter(followertl, reply_to_user_id == targettwitteruserid)
followertl <- transform(followertl, reply_to_status_id_num=as.numeric(reply_to_status_id))
join <- inner_join(followertl, tweetids, by=c("reply_to_status_id_num"="status_id_num"))
replycounts <- join %>%
group_by(reply_to_status_id_num) %>%
summarise(n=n())
master_reply_counts <- rbind(master_reply_counts, replycounts)
return(follower)
}
data <- ldply(targetfollowers$user_id, getfollowersreplies)