Search code examples
rtwitter

How to get number of twitter followers from a list of users with lookupuser() function


I'm trying to get the number of followers in twitter from some users that I already know. I'm using getuser() or lookupuser() but I don't get the info that I want.

I did a streamR to get info about some hashtag and then saved it in a .json file. Now I parsed it and one of the column that I see is "in_reply_to_screen_name", and I want to know the followers of those users.

I have done a subset to group all those name in a list, so I don't want to go one by one. I don't know why but getuser() function return an error, with list or just trying one user. Error: could not find function "getuser"

So I use lookupuser(), which is the same package, and seems like working but doesn't return the info that I'm looking for.

$notoliverbutler

[1] "notoliverbutler"

$OverTheMoonbat

[1] "OverTheMoonbat"

$OHenleyAlex

[1] "OHenleyAlex"

Example of the code:

subs1<-subset(tweet, (!is.na(tweet[,6]))
sublist<- c(subs1$in_reply_to_screen_name)
userinfo<- lookupUsers(sublist)
userinfo

I appreciate some help. Thanks in advance!

In this post they get the id, but I'm looking the number of followers: How to refer a variable name in getUser in twitteR R package?


Solution

  • The information should be in the user object from the twitteR package:

    user <- getUser("realDonaldTrump")
    class(user)
    # [1] "user"
    # attr(,"package")
    # [1] "twitteR"
    user$followersCount
    # [1] 30929590
    str(user$toDataFrame())
    # 'data.frame': 1 obs. of  17 variables:
    #  $ description      : chr "45th President of the United States of America"
    #  $ statusesCount    : num 34964
    #  $ followersCount   : num 30929590
    #  $ favoritesCount   : num 50
    #  $ friendsCount     : num 45
    #  $ url              : logi NA
    #  $ name             : chr "Donald J. Trump"
    #  $ created          : POSIXct, format: "2009-03-18 13:46:38"
    #  $ protected        : logi FALSE
    #  $ verified         : logi TRUE
    #  $ screenName       : chr "realDonaldTrump"
    #  $ location         : chr "Washington, DC"
    #  $ lang             : chr "en"
    #  $ id               : chr "25073877"
    #  $ listedCount      : num 69993
    #  $ followRequestSent: logi FALSE
    #  $ profileImageUrl  : chr "http://pbs.twimg.com/profile_images/1980294624/DJT_Headshot_V2_normal.jpg"
    
    users <- lookupUsers(c("IvankaTrump","realTrumpWomen"))
    sapply(users, function(x) x$followersCount)
     # IvankaTrump realTrumpWomen 
     #     3828630            656