我正在R中工作,并尝试为Twitter句柄列表提取喜欢和评论的总数。我完全一无所知,任何帮助将不胜感激。我已经设置了API并安装了必要的库。
任何线索都将不胜感激,谢谢
install.packages("twitteR")
library(twitteR)
install.packages("rtweet")
library(rtweet)
install.packages("tidytext")
library(tidytext)
install.packages("httr")
library(httr)
install.packages("RCurl")
library(RCurl)
install.packages("plyr")
library(plyr)
install.packages("RJSONIO")
library(RJSONIO)
install.packages("stringr")
library(stringr)
install.packages("ROAuth")
library(ROAuth)
#Setting up twitter API
consumer_key <- "key"
consumer_secret <- "key"
access_token <- "key"
access_secret <- "key"
options(httr_oauth_cache=T)
setup_twitter_oauth(consumer_key,
consumer_secret,
access_token,
access_secret)
#reading csv and extracting the followers and tweets count
users <- read.csv("Twitter.csv", skip = 1)
users1 <- lookupUsers(users[1:50,1])
答案 0 :(得分:0)
在R中,使用rtweet,以下是有关用户的信息
library(rtweet)
x <- rtweet::lookup_users("jdatap")
names(x)
[1] "user_id" "status_id" "created_at"
[4] "screen_name" "text" "source"
[7] "display_text_width" "reply_to_status_id" "reply_to_user_id"
[10] "reply_to_screen_name" "is_quote" "is_retweet"
[13] "favorite_count" "retweet_count" "hashtags"
[16] "symbols" "urls_url" "urls_t.co"
[19] "urls_expanded_url" "media_url" "media_t.co"
[22] "media_expanded_url" "media_type" "ext_media_url"
[25] "ext_media_t.co" "ext_media_expanded_url" "ext_media_type"
[28] "mentions_user_id" "mentions_screen_name" "lang"
[31] "quoted_status_id" "quoted_text" "quoted_created_at"
[34] "quoted_source" "quoted_favorite_count" "quoted_retweet_count"
[37] "quoted_user_id" "quoted_screen_name" "quoted_name"
[40] "quoted_followers_count" "quoted_friends_count" "quoted_statuses_count"
[43] "quoted_location" "quoted_description" "quoted_verified"
[46] "retweet_status_id" "retweet_text" "retweet_created_at"
[49] "retweet_source" "retweet_favorite_count" "retweet_retweet_count"
[52] "retweet_user_id" "retweet_screen_name" "retweet_name"
[55] "retweet_followers_count" "retweet_friends_count" "retweet_statuses_count"
[58] "retweet_location" "retweet_description" "retweet_verified"
[61] "place_url" "place_name" "place_full_name"
[64] "place_type" "country" "country_code"
[67] "geo_coords" "coords_coords" "bbox_coords"
[70] "status_url" "name" "location"
[73] "description" "url" "protected"
[76] "followers_count" "friends_count" "listed_count"
[79] "statuses_count" "favourites_count" "account_created_at"
[82] "verified" "profile_url" "profile_expanded_url"
[85] "account_lang" "profile_banner_url" "profile_background_url"
[88] "profile_image_url"
编辑
基于更新的代码。下面是一个可重现的示例。
users <- data.frame(
name = c("jdatap", "dataandme"),
stringsAsFactors = FALSE
)
rtweet::lookup_users
仅适用于character
类的对象
users <- data.frame(
name = c("jdatap", "dataandme")
)
class(users$name)
[1] "factor"
rtweet::lookup_users(users = users$name)
data frame with 0 columns and 0 rows
与此相反,向量为character
时一切正常。
users <- data.frame(
name = c("jdatap", "dataandme"),
stringsAsFactors = FALSE
)
rtweet::lookup_users
仅适用于character
类的对象
users <- data.frame(
name = c("jdatap", "dataandme"),
stringsAsFactors = FALSE
)
class(users$name)
[1] "character"
# works just not showing huge output here
users <- rtweet::lookup_users(users = users$name)
因此,当您使用read.csv
设置stringsAsFactors = FALSE
来读取csv时。
users <- read.csv("Twitter.csv", skip = 1, stringsAsFactors = FALSE)
请注意,以上内容基于rtweet
软件包,我强烈建议您按照twitteR
github page上的说明使用twitteR
进行切换。
这是twitteR相对悠闲的弃用期的开始,赞成使用rtweet。请开始寻找切换到该软件包的方法。如果您有任何疑问,请联系我自己或@mkearney