我正在尝试遍历csv文件中的所有名称,以便以下循环检索Twitter数据:
require(twitteR)
require(data.table)
consumer_key <- 'KEY'
consumer_secret <- 'CON_SECRET'
access_token <- 'TOKEN'
access_secret <- 'ACC_SECRET'
setup_twitter_oauth(consumer_key,consumer_secret,access_token,access_secret)
options(httr_oauth_cache=T)
accounts <- read.csv(file="FILE.CSV", header=FALSE, sep="")
Sample data in CSV file (each name in one only one row, first column):
timberghmans
alyssabereznak
JoshuaLenon
names <- lookupUsers(c(accounts))
for(name in names){
a <- getUser(name)
print(a)
b <- a$getFollowers()
print(b)
b_df <- rbindlist(lapply(b, as.data.frame))
print(b_df)
c <- subset(b_df, location!="")
d <- c$location
print(d)
}
然而,它不起作用。每个新行都包含一个twitter屏幕名称。当我输入如下:
names <- lookupUsers(c("USER1","USER2","USER3"))
它完美无缺。我也尝试循环帐户,但无济于事。有人可能有一个一般的例子,或者有人可以提示吗?