特定推文的转推计数 [英] Retweet count for specific tweet
问题描述
我正在使用TwitteR"包和 R 程序来检索推文信息.尽管 Twitter API 提供了
I'm using "TwitteR" package and R program to retrieve tweets information. Even though Twitter API provides
retweet_count’ function(https://dev.twitter.com/docs/faq#6899)
我不知道如何在 R 中使用它.(也许在 'RCurl' 包中使用了 'getURL
' 函数?)
I couldn't figure out how to utilize it within R. ( Maybe using 'getURL
' function in 'RCurl' package?)
基本上,我正在寻找方法
Basically, I'm looking for ways to
特定推文被转发的次数
the number of times specific tweet has been retweeted
在 R 中使用流式 API 获取实时信息,例如
Using Streaming API in R for getting real time information such as
一个.新关注者加入这些用户,并且
a. new followers join those users, and
B.当他们发布推文或转发时,以及
b. when they post tweets or retweets, and
c.当他们发布的推文被其他人转发时
c. when the tweets they have posted are re-tweeted by someone else
如果有人能帮我找到线索以获取任何这些信息,我将不胜感激.
I would appreciate if anyone could help me out finding leads to get any of these information.
推荐答案
我无法帮助解决流式 API 问题,但是基于 这个有用的教程.您可能可以使用它来专注于特定的推文,而不是每个用户的转发数量.此处的一些帖子可能更有用.
I can't help with the streaming API question, but how about this for working with retweets, based on this helpful tutorial. You could probably work with it to focus on specific tweets instead of numbers of retweets per user. Some of the posts here may be more useful.
# get package with functions for interacting with Twitter.com
require(twitteR)
# get 1500 tweets with #BBC tag, note that 1500 is the max, and it's subject to mysterious filtering and other restrictions by Twitter
s <- searchTwitter('#BBC', n=1500)
#
# convert to data frame
df <- do.call("rbind", lapply(s, as.data.frame))
#
# Clean text of tweets
df$text <- sapply(df$text,function(row) iconv(row,to='UTF-8')) #remove odd characters
trim <- function (x) sub('@','',x) # remove @ symbol from user names
#
# Extract retweets
library(stringr)
df$to <- sapply(df$to,function(name) trim(name)) # pull out who msg is to
df$rt <- sapply(df$text,function(tweet) trim(str_match(tweet,"^RT (@[[:alnum:]_]*)")[2]))
#
# basic analysis and visualisation of RT'd messages
sum(!is.na(df$rt)) # see how many tweets are retweets
sum(!is.na(df$rt))/length(df$rt) # the ratio of retweets to tweets
countRT <- table(df$rt)
countRT <- sort(countRT)
countRT.subset <- subset(countRT,countRT >2) # subset those RTd at least twice
barplot(countRT.subset,las=2,cex.names = 0.75) # plot them
#
# basic social network analysis using RT
# (not requested by OP, but may be of interest...)
rt <- data.frame(user=df$screenName, rt=df$rt) # tweeter-retweeted pairs
rt.u <- na.omit(unique(rt)) # omit pairs with NA, get only unique pairs
#
# begin sna
library(igraph)
g <- graph.data.frame(rt.u, directed = T)
ecount(g) # edges (connections)
vcount(g) # vertices (nodes)
diameter(g) # network diameter
farthest.nodes(g) # show the farthest nodes
这篇关于特定推文的转推计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!