在 R 中查找 Twitter 关注者 [英] Lookup Twitter followers in R

查看:35
本文介绍了在 R 中查找 Twitter 关注者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 R 查找用户的 Twitter 关注者的个人资料(关注者 > 100000).尽管 twitteR 是一个很棒的软件包,但它在处理大量关注者时存在问题,因为人们需要实施睡眠程序以避免超过速率限制.我是这里的相对新手,想知道如何遍历关注者 ID 对象,以 100 个为一组输入关注者 ID(因为这是 Twitter API 一次可以处理的最大值)?

I'd like to look up the profiles of a user's Twitter followers using R (followers > 100000). Although twitteR is a great package, it has problems when dealing with high levels of followers as one needs to implement a sleep routine to avoid exceeding the rate limits. I am a relative novice here and wondered how one might loop through the follower ID object, entering in follower ids in batches of 100 (as this is the max the Twitter API can process at a time)?

添加了代码(推特)图书馆(plyr)maxTwitterIds = 100睡眠时间 = 500 # 秒

code added (twitteR) library(plyr) maxTwitterIds = 100 sleeptime = 500 # sec

user<-getUser("[username]")
followers<-zz$getFollowerIDs()
ids_matrix = matrix(zz, nrow = maxTwitterIds, ncol = length(zz) / maxTwitterIds)
followers<-zz$getFollowerIDs()
#note: for smaller lists of followers it is possible to use the command "lookupUsers(zz)     at this point
foll<-getTwitterInfoForListIds = function(id_list) {
    return(lapply(id_list, 

names <- sapply(foll,name)
sn<sapply(foll,screenName)
id<-sapply(foll,id)
verified<-sapply(foll,erified)
created<-sapply(foll,created)
statuses<-sapply(foll,statusesCount)
follower<-sapply(foll,followersCount)
friends<-sapply(foll,friendsCount)
favorites<-sapply(foll,favoritesCount)
location<-sapply(foll,location)
url<-sapply(foll,url)
description<-sapply(foll,description)
last_status<-sapply(foll,lastStatus)))
}
alldata = alply(, 2, function(id_set) {
    info = getTwitterInfoForListIds(id_set)
    Sys.sleep(sleeptime)   
    return(info)
})

推荐答案

这也可以使用较新的 rtweet 包来完成.

This can also be done using the newer rtweet package.

根据此处的示例:https://github.com/mkearney/rtweet

# Get followers 

# Retrieve a list of the accounts following a user.

## get user IDs of accounts following CNN 
cnn_flw <- get_followers("cnn", n = 75000)

# lookup data on those accounts 
cnn_flw_data <- lookup_users(cnn_flw$user_id) 

# Or if you really want ALL of their followers:
# how many total follows does cnn have? 
cnn <- lookup_users("cnn")
# get them all (this would take a little over 5 days) 
cnn_flw <- get_followers(   "cnn", n = cnn$followers_count, 
  retryonratelimit = TRUE )

这篇关于在 R 中查找 Twitter 关注者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆