1
votes

I need to get tweets that contain at least of the following hashtags: #EUwahl #Euwahlen #Europawahl #Europawahlen. This means, I am looking for tweets containing at least one of those hashtags but they can also contain more of them. Furthermore, in each of these tweets one out of seven specific user (eg @AfD) must be mentioned as well in the tweet.

So far I only know how to search Twitter for one hashtag only or several ones. Meaning, I am familiar with the operator and using a + between the hashtags but not with the operator for or.

This is an example of a code I have used so far to do any searches in Twitter:

euelection <- searchTwitter("#EUwahl", n=1000, since = "2019-05-01",until = "2019-05-26")
1
Hi Laura, can you include the package, is it twitteR? Since you mention you know how to use "+", or is "|" in R, so you want to try that and say what you like to search ? For example tweets with #EUwahl or #Euwahlen - StupidWolf
Hi @StupidWolf, I'm sorry I forgot to mention that I am working with the package twitteR. But appearantly the + operator does not work, so therefore also the | operator does not. In the end I would like to get a dataset out of the tweets which include one (or more) of the mentioned hashtag regarding the EU election 2019 AND additionally address one of the German parties represented in the EU parliament (eg @CDU) in the same tweet. So far I only know how to search twitter for one hashtag, keyword etc. Is this possible with twitteR or do I need another package? Thank you for your help! - Laura
ok i post an answer below because it's too long to type. Use "#EUwahl OR #Euwahlen", this should work. I guess for what you do, you need twitteR. Maybe you try first and see whether it works? - StupidWolf

1 Answers

1
votes

I can install twitteR but it requires some authentication key which is not very easy for me to get.

The principle is to search using OR with space in between. I provide you an example with rtweet

library(rtweet)
# your tags
TAGS = c("#EUwahl","#Europawahl")
# make the search term
SEARCH = paste(TAGS,collapse=" OR ")
# do the search
# you can also use twitteR
test <- search_tweets(SEARCH, n=100)
# your found tweet text
head(test$text)
## check which tweet contains which tag
tab = sapply(TAGS,function(i)as.numeric(grepl(i,test$text,ignore.case=T)))
# all of them contain either #EUwahl or #Europawahl