最近 twitter 已将推文的字符数限制扩展为 280个字符。 从那时起, TwitteR 包仅检索(或显示,IDK)扩展推文的初始 140 字符。
# load package
library(twitteR)
# set oauth
setup_twitter_oauth(Consumer_Key,Consumer_Secret,Access_Token,Access_Token_Secret)
# get user timeline
k<-userTimeline("SenateFloor", n = 50, includeRts = T)
# to data frame
k<-twListToDF(k)
# print tweet text
print(k$text[1:5])
控制台输出
[1] "#Senate in at 4:00 PM. Following Leader remarks, will proceed to Executive Session & resume consideration of Cal. #… https:// t.co/BpcPa15Twp"
[2] "RT @GovTop: Weekly Digest of the #CongressionalRecord https:// t.co/vuH71y8FpH"
[3] "#HJRes123 ( Making further continuing appropriations for fiscal year 2018). The Joint Resolution was agreed to by a… https:// t.co/bquyMPPhhm"
[4] "#HJRes123 ( Making further continuing appropriations for fiscal year 2018). https:// t.co/SOmYJ3Dv4t"
[5] "Cal. #167, Susan Bodine to be Assistant Administrator of the Environmental Protection Agency. The nomination was co… https:// t.co/pW7qphwloh"
正如你所看到的,一个省略号(...)会削减超过140限制的推文。
> nchar(k2$text[1:5])
[1] 144 77 140 99 140
有没有办法从这些扩展推文中获取整篇文章?
答案 0 :(得分:3)
如评论中所述,只需使用rtweet
:
library(rtweet)
library(tidyverse)
sen_df <- get_timeline("SenateFloor", 300)
mutate(sen_df, `Tweet Length`=map_dbl(text, nchar)) %>%
ggplot(aes(`Tweet Length`)) +
ggalt::geom_bkde(color="steelblue", fill="steelblue", alpha=2/3) +
scale_y_continuous(expand=c(0,0)) +
labs(title="@SenateFloor Tweet Length Distribution") +
hrbrthemes::theme_ipsum_rc(grid="XY")
答案 1 :(得分:0)
如果您想继续使用twitteR,那么您可以试试这个:
# get user timeline
k<-userTimeline("SenateFloor", n = 50, includeRts = T, tweet_mode = "extended")