Reputation: 2513
Using twitteR package: https://cran.r-project.org/web/packages/twitteR/twitteR.pdf
Connecting to twitter API:
library (twitteR)
consumer_key <- "xxxx"
consumer_secret <- "xxxx"
access_token <- "xxxx"
access_secret <- "xxxx"
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
Getting a collection of 10 relevant tweets matching #nantes query:
nantes_tag <- searchTwitter("#nantes", n =10)
nantes_tag <- twListToDF(nantes_tag) # converting to df
Extracting id's vector from my data.frame object:
user_id <- nantes_tag$id
A short output:
user_id <- c("800684281337147392",
"800684281295212544",
"800684084687228928",
" 800684024406609923",
"800683967884050432")
How can I get user's information for each id using getuser()
function and store them in a data.frame object?
I tried without success:
users <- lookupUsers(user_id)
Can I make a loop over user_id
with get_user()
?
Upvotes: 2
Views: 3990
Reputation: 388982
Instead of using the Id
's , I would suggest you to use the screen names
of the users
usernames <- nantes_tag$screenName
and then pass character vector of these screen names to lookupUsers
and then wrap it around twListToDF
to get the required output in dataframe format.
temp_df <- twListToDF(lookupUsers(usernames))
Upvotes: 3