Rtweet get_timeline no longer showing user_id or screen_name

I am looking to pull a set of Tweets for multiple users, the rtweet package. When I have used the get_timeline() function previously, the output has included the user_id and screen_name of the account. This is particularly important when pulling Tweets for multiple users so that you can identify who the Tweet belongs to.

However, in the recent update, this function no longer pulls any identifying user information. We now get id and id_str which are unique to the Tweet but don’t tell us whose timeline we are pulling from. Any idea how to reattach a screen_name to the output or a way to identify the output?

accounts <- c("BarackObama", "justinbieber")
timelines <- get_timeline(accounts, n = 100, token = auth, retryonratelimit = TRUE)
id id_str
1.436416e 1436416270426050566
1.437194e 1437194052122906626

The current version of rtweet does pull the identifying user information. It might be useful to read the post I wrote about the update of the package: rOpenSci | Upgrading rtweet .

In short, you must use users_data(timelines) to visualize information about users from those endpoints that provide tweet data. You can reattach it with:

accounts <- c("BarackObama", "justinbieber")
timelines <- get_timeline(accounts, n = 100, token = auth, retryonratelimit = TRUE)
users_timelines <- users_data(timelines)
cbind(timelines, users_timelines[, c("id", "id_str", "name", "screen_name")])

In future version I’ll try to make it easier to find and relate this information.

Thanks for taking a look at this. We are getting closer. However, in the code you provided, users_data(timelines) only pulled information for BarackObama and then the cbind only appended on his information to all lines, even though half of the tweets were from Barack Obama and half were from Justin Bieber. It looks like the main issue is that users_data is only pulling user information for one account (rather than the two accounts that make up timelines).

1 Like

Oh, sorry, this is a bug in rtweet: users’ data is dropped in get_timeline when multiple users are provided. I opened a bug in the repository to fix it: get_timeline for multiple users do not have all the users_data · Issue #723 · ropensci/rtweet · GitHub.

To avoid this problem until I fix it in next release I would recommend to search for each one user each time:

timeline_bo <- get_timeline("BarackObama", n = 100, token = auth, retryonratelimit = TRUE)
timeline_jb <- get_timeline("justinbieber", n = 100, token = auth, retryonratelimit = TRUE)

bo <- cbind(timeline_bo, users_data(timeline_bo)[, c("id", "id_str", "name", "screen_name")])
jb <- cbind(timeline_jb, users_data(timeline_jb)[, c("id", "id_str", "name", "screen_name")])
timeline_with_users <- rbind(bo, jb)
1 Like

I fixed this in the devel version of rtweet version 1.0.2.9004 (in the devel branch in github). Next release shouldn’t have this problem

1 Like

Thanks for the update! I downloaded the development version of rtweet from github (though it said it was version still 1.0.2) and it was still having the same issue. Is there is a way for me to access this update?

The current development version of rtweet is in github on the devel branch. Probably you installed the version from the default branch.

You can install the latest version with: remotes::install_github("ropensci/rtweet@devel")

Thanks. I tried to install with remotes::install_github("ropensci/rtweet@devel"). Installation was successful but screen_name is still not loaded when I use get_timeline.

I also note that ?get_timelineno longer gives me the help file for the get_timeline function. I don’t know if that is a significant clue to why get_timeline still does not load screen_name.

Dear cortexR.

The screen_name should be hidden, see this blog post for more background information. Did you use users_data(timeline) and didn’t get that column? Could you provide a reproducible example with the version of the package you are using?

The development version is might have problems and errors in it. However, the help page of get_timeline was accessible for me with ?get_timeline.

Thanks a lot. That blog post explains it. Instead of using get_timeline I just need to change code to use users_data() and tweets_data() and then bind them with cbind to get screen_name into the data about users latest tweets.

PS: In the blog post, there seems to be a minor error. Instead of users_and_last_tweets <- cbind(users, id_str = tweets_data(users)[, "id_str"]), it should be users_and_last_tweets <- cbind(users, tweets_data(users) ,id_str = tweets_data(users)[, "id_str"]). (I.e. the second data to bind was missing).

@cortexR The data about the users is already in the output of get_timeline, users_data only retrieves the attribute where it is “hidden”.

It is no error, it is just an example on where and how to “add” data. I made the decision when retrieving users data to only display user data and when searching tweets only display tweet data. Packages and users might need or not that other data or would like one way or another.

1 Like