ropensci / rtweet

🐦 R client for interacting with Twitter's [stream and REST] APIs
https://docs.ropensci.org/rtweet
Other
785 stars 202 forks source link

inserting data from dataframe #93

Closed hussainshehadeh closed 7 years ago

hussainshehadeh commented 7 years ago

Hello,

I am collecting all tweets that have this specific tweet:

TweetsRT <- search_tweets("RT @kendricklamar", n=15000)

Then what I want is to collect the people who tweeted these tweets and collect their followers. I am using this function:

FollowersOfUser <- get_followers(578634357, n= "all", page = "-1", parse = TRUE, as_double = FALSE, token = NULL)

But is there a way where instead of inserting the user id manually, I can do it automatically?

I need a list of all the users in TweetsRT and their followers. How can I do it?

mkearney commented 7 years ago

Yes. If you have a tweets data frame, then you can pass values from user_id or screen_name columns into get_followers.


## first, I recommend upgrading to Github version (at this moment in time, at least; 
## I'm overdue for a CRAN update).
if (!"devtools" %in% installed.packages()) {
  install.packages("devtools")
}
devtools::install_github("mkearney/rtweet")

## grab tweets
rt <- search_tweets("RT @KendrickLamar", n = 15000)
## Due to rate limits you may only be able to do this a few times (maybe 15?) every 15 mins.
flw <- lapply(
  rt$user_id[1:15], get_followers)

## convert to data frames 
usr_df <- do.call("rbind", lapply(rt, users_data))
twt_df <- do.call("rbind", rt)
hussainshehadeh commented 7 years ago

Is there a way where get_followers function can give me screen_name instead of user_id

mkearney commented 7 years ago

I'm afraid not. But the rate limit on lookup_users is quite high, so passing the IDs on shouldn't take too long that way. I actually backdoored a webscraper to do this same thing and found out working with the public API was fastest.

mrmvergeer commented 7 years ago

Alternatively, one could get the screennames by collection the Twitter profile data using the user ids

BTW great work Michael