如何使用 twitteR 时间线获取更多数据
How to get more data with twitteR timeline
我需要导出 100 个用户的推特时间线,我需要 2014 年的所有推文。
我是第一次使用 R,我能够 运行 时间线功能并检索单个用户的所有最后 N 条推文。问题是我需要更多数据,比如时间戳、转发次数、收藏次数 ecc。
我该怎么做?
我使用的函数是:
userTimeline('username', n=200, maxID=NULL, sinceID=NULL, includeRts=TRUE)
都在那里:
library(twitteR)
# ... authorize ...
tl <- userTimeline('lukeanker', n=6)
df <- do.call(rbind, lapply(tl, function(x) x$toDataFrame()))
names(df)
# [1] "text" "favorited" "favoriteCount" "replyToSN" "created" "truncated" "replyToSID"
# [8] "id" "replyToUID" "statusSource" "screenName" "retweetCount" "isRetweet" "retweeted"
# [15] "longitude" "latitude"
df[, c("created", "retweetCount")]
# created retweetCount
# 1 2015-03-05 13:50:44 0
# 2 2015-02-19 15:51:47 0
# 3 2015-02-17 17:36:01 0
# 4 2015-02-17 17:35:03 0
# 5 2015-02-12 16:49:29 0
# 6 2015-02-11 10:29:35 0
或者,另一种方式是
获取包含所有信息的@HillaryClinton 推文。最多 3200
clinton_tweets <- userTimeline("HillaryClinton", n = 3200)
将 twitteR 列表转换为 data.frames
的函数
tweetsc.df <- twListToDF(clinton_tweets)
然后只需打开 tweetsc.df 并查看所有结果
我需要导出 100 个用户的推特时间线,我需要 2014 年的所有推文。 我是第一次使用 R,我能够 运行 时间线功能并检索单个用户的所有最后 N 条推文。问题是我需要更多数据,比如时间戳、转发次数、收藏次数 ecc。 我该怎么做? 我使用的函数是:
userTimeline('username', n=200, maxID=NULL, sinceID=NULL, includeRts=TRUE)
都在那里:
library(twitteR)
# ... authorize ...
tl <- userTimeline('lukeanker', n=6)
df <- do.call(rbind, lapply(tl, function(x) x$toDataFrame()))
names(df)
# [1] "text" "favorited" "favoriteCount" "replyToSN" "created" "truncated" "replyToSID"
# [8] "id" "replyToUID" "statusSource" "screenName" "retweetCount" "isRetweet" "retweeted"
# [15] "longitude" "latitude"
df[, c("created", "retweetCount")]
# created retweetCount
# 1 2015-03-05 13:50:44 0
# 2 2015-02-19 15:51:47 0
# 3 2015-02-17 17:36:01 0
# 4 2015-02-17 17:35:03 0
# 5 2015-02-12 16:49:29 0
# 6 2015-02-11 10:29:35 0
或者,另一种方式是
获取包含所有信息的@HillaryClinton 推文。最多 3200
clinton_tweets <- userTimeline("HillaryClinton", n = 3200)
将 twitteR 列表转换为 data.frames
的函数tweetsc.df <- twListToDF(clinton_tweets)
然后只需打开 tweetsc.df 并查看所有结果